2014-08-29 124 views
0

我寫了一個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倍左右,你會看到,它是無法完成的,至少沒有幾次警告或錯誤...

+0

你在Windows或Linux上運行這個? – mishu 2014-08-29 07:42:04

+0

我在問,因爲在Windows上下載頁面所花的時間被認爲是執行時間,請參閱http://php.net/set_time_limit – mishu 2014-08-29 07:46:04

+0

Ubuntu GNOME 14.04 – user3331119 2014-08-29 07:50:08

回答

0

Ubuntu已經執行了一堆系統更新。更新完成後,我正在處理代碼。系統重啓後,這個問題完全消失了。去搞清楚。