简体   繁体   English

为什么curl会忽略CURLOPT_TIMEOUT_MS(但是尊重CURLOPT_TIMEOUT)?

[英]Why would curl ignore CURLOPT_TIMEOUT_MS (but honor CURLOPT_TIMEOUT)?

I am using curl to call a web service API. 我使用curl来调用Web服务API。 The service can unresponsive so I want to set a timeout. 该服务可以无响应,所以我想设置超时。 When I use CURLOPT_TIMEOUT things work as expected. 当我使用CURLOPT_TIMEOUT时,事情按预期工作。 But when I use CURLOPT_TIMEOUT_MS (note the 'MS' for milliseconds) the timeout doesn't appear to kick in at all. 但是当我使用CURLOPT_TIMEOUT_MS(注意'MS'为毫秒)时,超时似乎根本没有启动。 php.net tells me that the latter was available since PHP version 5.2.3, and I am using 5.2.6. php.net告诉我后者自PHP 5.2.3版本开始可用,我使用的是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. 我正在使用的curl版本(7.15.5)不支持CURLOPT_TIMEOUT_MS。 According to Greg I need at least 7.16.2. 据格雷格说我至少需要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. 我观察到,类似的问题在运行curl版本4.3.0的CentOS 5.4系统上,似乎每当curl构建为使用'标准系统名称解析器'时,这种行为就会出现。

Work around is to use 'CURLOPT_NOSIGNAL' option along with 'CURLOPT_TIMEOUT_MS'; 解决方法是使用'CURLOPT_NOSIGNAL'选项和'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/ 查看以下页面的详细信息: https//ravidhavlesha.wordpress.com/2012/01/08/curl-timeout-problem-and-solution/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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