简体   繁体   中英

Why would curl ignore CURLOPT_TIMEOUT_MS (but honor CURLOPT_TIMEOUT)?

I am using curl to call a web service API. The service can unresponsive so I want to set a timeout. When I use CURLOPT_TIMEOUT things work as expected. But when I use CURLOPT_TIMEOUT_MS (note the 'MS' for milliseconds) the timeout doesn't appear to kick in at all. php.net tells me that the latter was available since PHP version 5.2.3, and I am using 5.2.6.

Any ideas why this is happening?

Thanks.

Code fragment:

$c = curl_init();
curl_setopt( $c, CURLOPT_URL, $call );
curl_setopt( $c, CURLOPT_HTTPHEADER, $headers); 
curl_setopt( $c, CURLOPT_HEADER, false );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $c, CURLOPT_TIMEOUT_MS, 100 ); 
curl_setopt( $c, CURLOPT_CONNECTIONTIMEOUT_MS, 100 ); 
$result = curl_exec($c);
curl_close($c);

To close this question:

The version of curl I am using (7.15.5) doesn't support CURLOPT_TIMEOUT_MS. According to Greg I need at least 7.16.2.

I have observed, similar issue on CentOS 5.4 system running curl version 4.3.0 and it seems whenever curl is built to use 'standard system name resolver', this behaviour kicks in.

Work around is to use 'CURLOPT_NOSIGNAL' option along with 'CURLOPT_TIMEOUT_MS'; however this may have it's own consequences.

Check out details on following page: https://ravidhavlesha.wordpress.com/2012/01/08/curl-timeout-problem-and-solution/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM