PHP Curl随机挂起
问题描述:
我写了一个PHP脚本,它卷曲了URL以获取页面html。页面内容大约有50%的时间回来,剩下的时间只有部分内容被返回,脚本无法终止。我没有得到任何错误......对CLIPHP Curl随机挂起
$headers = array(
'Accept-Language: en-US,en;q=0.8',
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36',
'Content-Type: application/x-www-form-urlencoded',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com/channel/UCkN6ktadXpZl_viwRCSEGUQ');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$curl_info = curl_getinfo($ch);
$response = curl_exec($ch);
curl_close($ch);
print $response;
print_r($curl_info);
运行:
php script_name.php
如果跑了10倍左右,你会看到,它是无法完成的,至少没有几次警告或错误...
答
Ubuntu已经执行了一堆系统更新。更新完成后,我正在处理代码。系统重启后,这个问题完全消失了。去搞清楚。
你在Windows或Linux上运行这个? – mishu 2014-08-29 07:42:04
我在问,因为在Windows上下载页面所花的时间被认为是执行时间,请参阅http://php.net/set_time_limit – mishu 2014-08-29 07:46:04
Ubuntu GNOME 14.04 – user3331119 2014-08-29 07:50:08