Curl connection to remote server timeout once in a while, however when I take a tcpdump, it shows that the server actually responded even though the curl request had timed out. Is this a tcp behaviour? Below is a sample server side php code to simulate the behaviour, file named test.php and deployed on Nginx with PHP-FPM.
<?php
sleep(10);
echo "Hello World";
Below is a curl request with a 5seconds timeout.
curl -m 5 'http://server_ip:port/test.php'
Below is a sample client side script that can be used in place of the above
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://server_ip:port/test.php');
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if (curl_errno($curl) > 0)
{
echo curl_error($curl), curl_errno($curl), PHP_EOL;
}
else
{
echo $response, PHP_EOL;
}
curl_close($curl);
tcpdump -w timeout_1.pcap -s0 -v -tttt -i eth0 host
The tcpdump was taken on the client machine.