热搜:NVER node 开发 php

关于php curl超时问题

2024-07-21 16:05:01
关于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错误为什么?


回复讨论(解决方案)

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