为什么curl会忽略CURLOPT_TIMEOUT_MS(但是荣誉CURLOPT_TIMEOUT)? [英] Why would curl ignore CURLOPT_TIMEOUT_MS (but honor CURLOPT_TIMEOUT)?

查看:2687
本文介绍了为什么curl会忽略CURLOPT_TIMEOUT_MS(但是荣誉CURLOPT_TIMEOUT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用curl来调用Web服务API。服务可能无响应,所以我想设置超时。当我使用CURLOPT_TIMEOUT的东西工作按预期。但是当我使用CURLOPT_TIMEOUT_MS(注意'MS'毫秒)超时似乎没有踢。 php.net告诉我,后者从PHP版本5.2.3开始可用,我使用的是5.2.6。

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?

感谢。

代码片段:

$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);


推荐答案

要关闭此问题:

我使用的curl版本(7.15.5)不支持CURLOPT_TIMEOUT_MS。根据Greg我需要至少7.16.2。

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.

这篇关于为什么curl会忽略CURLOPT_TIMEOUT_MS(但是荣誉CURLOPT_TIMEOUT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆