卷曲错误:操作超时 [英] Curl error: Operation timed out

查看:485
本文介绍了卷曲错误:操作超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Curl时,出现以下致命错误:

I have the following fatal error when trying to use Curl:

PHP Fatal error:  Uncaught HTTP_Request2_MessageException: 
Curl error: Operation timed out after 30000 milliseconds with 0 bytes received in      
/usr/share/php/HTTP/Request2/Adapter/Curl.php on line 200
Exception trace    Function       Location
0                  HTTP_Request2_Adapter_Curl::wrapCurlError('Resource id #12') 
                   /usr/share/php/HTTP/Request2/Adapter/Curl.php:200
1                  HTTP_Request2_Adapter_Curl->sendRequest(Object(HTTP_Request2))
/usr/share/php/HTTP/Request2.php:959< in /usr/share/php/HTTP/Request2/Adapter/Curl.php on line 172

但是,我看不出如何最好地调试它。没有对任何代码行的引用,只有 HTTP_Request2 Curl 模块。

However, I can't see how to best debug it. There's no reference to any line of code I've written, only the HTTP_Request2 and Curl modules. What's the best approach to try and resolve this?

推荐答案

您的curl会超时。

Your curl gets timed out. Probably the url you are trying that requires more that 30 seconds.

如果您通过浏览器运行脚本,请设置 set_time_limit 到零为无限秒。

If you are running the script through browser, then set the set_time_limit to zero for infinite seconds.

set_time_limit(0);

使用此选项增加curl的操作时间限制 CURLOPT_TIMEOUT

Increase the curl's operation time limit using this option CURLOPT_TIMEOUT

curl_setopt($ch, CURLOPT_TIMEOUT,500); // 500 seconds

它也可以发生在从服务器无限重定向。要停止此尝试,请运行禁用跟踪位置的脚本。

It can also happen for infinite redirection from the server. To halt this try to run the script with follow location disabled.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

这篇关于卷曲错误:操作超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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