简体   繁体   English

PHP卷曲超时错误检测

[英]PHP curl timeout error detection

I use curl to perform a HTTP request like this: 我使用curl来执行这样的HTTP请求:

$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);

$data = curl_exec($ch);
curl_close($ch);

How can I check if an error occurred, and whether it was a timeout error? 如何检查是否发生错误,以及是否为超时错误?

Use curl_errno() 使用curl_errno()

Code 28 is timeout. 代码28是超时。

you can check error number and its' description like this: 你可以检查错误号码及其描述如下:

// Check if any error occurred
if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}

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

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