Hello All,
We tried to use curl to make HTTP post request with json data to internal micro-service which use Slim framework. But curl returns with empty reply randomly. Even in that case, the micro-service got the request and handles it successfully.
And we’re getting same issues with/without apache mod_rewrite engine for url rewriting.
Any help would be appreciated.
Thanks in advance.
- Service environment
PHP : 5.5.38
Apache : 2.2.3
Slim : 3.7.0
- Here is the code snippet how we make the curl request in php.
$curl = curl_init();
$encodedData = json_encode($data);
$curlOption = [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 10,
CURLOPT_POST => 1,
CURLOPT_HEADER => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_HTTPHEADER => [
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($encodedData),
'Expect: ’
];
CURLOPT_POSTFIELDS => $encodedData,
CURLOPT_FRESH_CONNECT => 1
];
curl_setopt_array($curl, $curlOption);
$response = curl_exec($curl);
if ($response === false) {
$error = curl_error($curl);
$curlInfo = curl_info($curl);
error_log("error : ". $error);
error_log("curl_info : " . var_export($curInfo, true);
} else {
// handle response
}
- microservice directory structure
/microservice/service1/lib/slim => slim framework
/microservice/service1/www/html => web document root
api.php
.htaccess
- Below is curl verbose result when we got empty reply from microservice.
Trying x.x.x.x…
Connected to x.x.x.x (x.x.x.x) port 80 (#0)
POST /service/www/html/api.php/abc HTTP/1.1
Host: x.x.x.x
Accept: /
Content-Type: application/json
Content-Length: 31006
upload completely sent off: 31006 out of 31006 bytes
Empty reply from server
Connection #0 to host x.x.x.x.com left intact
- error string and dump of curl_info.
error : Empty reply from server
curl_info : array (
‘url’ => ‘http://x.x.x.x/api.php/abc’,
‘content_type’ => NULL,
‘http_code’ => 0,
‘header_size’ => 0,
‘request_size’ => 31180,
‘filetime’ => -1,
‘ssl_verify_result’ => 0,
‘redirect_count’ => 0,
‘total_time’ => 0.143499999999999960920149533194489777088165283203125,
‘namelookup_time’ => 0.038522000000000000685673740008496679365634918212890625,
‘connect_time’ => 0.04020300000000000262279087337446981109678745269775390625,
‘pretransfer_time’ => 0.040597000000000001140865180104810860939323902130126953125,
‘size_upload’ => 31006,
‘size_download’ => 0,
‘speed_download’ => 0,
‘speed_upload’ => 216069,
‘download_content_length’ => -1,
‘upload_content_length’ => 31006,
‘starttransfer_time’ => 0.14344699999999999118216464921715669333934783935546875,
‘redirect_time’ => 0,
‘redirect_url’ => ‘’,
‘primary_ip’ => ‘x.x.x.x’,
‘certinfo’ =>
array (
),
‘primary_port’ => 80,
‘local_ip’ => ‘x.x.x.x’,
‘local_port’ => x,
)
error : Empty reply from server