2012-12-14 26 views
2
$query = "https://api.facebook.com/method/fql.query?format=JSON&query="; 
$urls = array('about 500 link'); 
foreach ($urls as $url) 
{ 
    $query .= urlencode("select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ='$url')"); 
    $query .= "&pretty=1"; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $query); 
    curl_setopt($ch, CURLOPT_TIMEOUT ,900); 
    $data = curl_exec($ch); 
    $response = json_decode($data, true); 
    echo '<pre>';print_r($response);echo '</pre>'; 
    curl_close($ch); 
} 

當我雖然在$urls陣列大約500鏈接運行這段代碼,我得到一個錯誤的結果:ERROR 500 - Internal Server Error,但$urls只包含5個環節,沒有任何錯誤。如何獲得所有500個鏈接的內容而不超時?錯誤500內部服務器何時使用CURL php獲取數據?

+0

「當運行代碼大約500個鏈接「意味着你使用包含500個URL的'$ urls'運行代碼? – hek2mgl

+0

對我來說,問題出在URL上。我在URL末尾添加了尾部斜槓(/),它工作正常。不知道這是否正確,Facebook將它視爲相同的網址? – aur1mas

回答

2

這不是curl錯誤,這是您的服務器錯誤,因爲請求持續時間有限制。請求500頁需要一段時間,並且腳本終止。請嘗試以下操作:

  1. 設置set_time_limit(200);以上
  2. 運行使用SSH連接的腳本,有一個在所有
  3. 使用curl_multi_init沒有超時做多個請求並行