Home >Backend Development >PHP Tutorial >关于php curl超时问题

关于php curl超时问题

WBOY
WBOYOriginal
2016-06-23 13:08:321258browse

我用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错误为什么?


回复讨论(解决方案)

http://blog.csdn.net/henriezhang/article/details/38308413

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

curl_setopt($curl, CURLOPT_TIMEOUT,60);

你设置的是60秒,一分钟。

你的问题时服务器设置了php最大执行时间时30秒,可以用以下语句修改
在php文件中,加入
ini_set('max_execution_time', '300'); 改为300秒

或修改php.ini
max_execution_time = 300

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP之基础篇1Next article:PHP+Swoole及时通讯