【问题标题】:Error 500 Internal Server when get data using CURL php?使用 CURL php 获取数据时出现错误 500 内部服务器?
【发布时间】:2012-12-14 10:28:52
【问题描述】:
$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 个链接的内容?

【问题讨论】:

  • 'When run code about 500 link'表示您使用包含一组 500 个 url 的 $urls 运行代码?
  • 对我来说问题出在 URL 上。我在 URL 的末尾添加了斜杠 (/),它起作用了。不知道它是否正确 & Facebook 将其视为相同的 url?

标签: php facebook curl facebook-comments


【解决方案1】:

这不是 curl 错误,这是您的服务器错误,因为请求持续时间有限制。请求 500 页需要一段时间,并且您的脚本会终止。请尝试以下操作:

  1. 设置set_time_limit(200);或更多
  2. 使用SSH连接运行脚本,完全没有超时
  3. 使用curl_multi_init并行执行多个请求

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2015-07-05
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多