$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个链接的内容?
答案 0 :(得分:2)
这不是卷曲错误,这是您的服务器错误,因为请求持续时间有限制。请求500页需要一段时间,您的脚本将终止。请尝试以下方法:
set_time_limit(200);
或更多curl_multi_init
并行执行多项请求