问题:关于php curl超时问题
描述:

我用curl写了一个get获取返回状态的代码

function http_get_code($url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT,60); 
    curl_setopt($curl,CURLOPT_NOBODY,true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    $recode=curl_getinfo($curl,CURLINFO_HTTP_CODE);
    curl_close($curl);
    return $recode;
}

明明设置了超时为1秒,但是有个不开放80端口的网址运行到curl_exec处还是报Maximum execution time of 30 seconds exceeded in错误为什么?
解决方案1:

curl_setopt($curl, CURLOPT_TIMEOUT,60);
你设置的是60秒,一分钟。
你的问题时服务器设置了php最大执行时间时30秒,可以用以下语句修改
在php文件中,加入
ini_set('max_execution_time', '300'); 改为300秒
或修改php.ini
max_execution_time = 300

解决方案2:

明明是 curl_setopt($curl, CURLOPT_TIMEOUT,60);
怎么能说 1 秒,说一分钟才对

上一篇php如何给value传数据?
下一篇PHPstorm 中文字符出现乱码
明星图片
相关文章
《关于php curl超时问题》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)