卷曲错误:操作超时

ali*_*s51 14 php curl

尝试使用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
Run Code Online (Sandbox Code Playgroud)

但是,我看不出如何最好地调试它.没有提到我编写的任何代码行,只有HTTP_Request2Curl模块.尝试解决此问题的最佳方法是什么?

Sab*_*san 33

你的卷发会超时.可能你正在尝试的网址需要30秒以上.

如果您通过浏览器运行脚本,则将set_time_limit无限秒设置为零.

set_time_limit(0);
Run Code Online (Sandbox Code Playgroud)

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

curl_setopt($ch, CURLOPT_TIMEOUT,500); // 500 seconds
Run Code Online (Sandbox Code Playgroud)

从服务器进行无限重定向也会发生这种情况.要暂停此操作,请尝试在禁用后续位置的情况下运行脚本.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
Run Code Online (Sandbox Code Playgroud)

  • 5年后这仍然对我有帮助。谢谢你! (3认同)