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獲取數據?
「當運行代碼大約500個鏈接「意味着你使用包含500個URL的'$ urls'運行代碼? – hek2mgl
對我來說,問題出在URL上。我在URL末尾添加了尾部斜槓(/),它工作正常。不知道這是否正確,Facebook將它視爲相同的網址? – aur1mas