【问题标题】:Slow response of Insagram API when using file_get_contents()使用 file_get_contents() 时 Insagram API 响应缓慢
【发布时间】:2019-03-27 08:16:17
【问题描述】:

我正在使用旧的 Instagram API。 如果我使用 cUrl,它工作得很快,但我必须使用套接字或 file_get_contents() - 然后需要 10 多秒才能响应。

我尝试发送各种标头,例如“连接:关闭”并使用 http 1.0/1.1 - 但没有任何帮助。

这里的代码示例:

cUrl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.instagram.com/v1/users/self/?access_token=some_token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$res = curl_exec($ch);
curl_close($ch);
print_r($res);

file_get_contents()

$res = file_get_contents("https://api.instagram.com/v1/users/self/?access_token=some_token");
print_r($res);

【问题讨论】:

  • @zvi 我认为这不是 DNS 问题,因为当我使用 cUrl 时它运行得很快。我也尝试发送“连接:关闭”标头,但没有帮助。我正在运行 PHP 7.1

标签: php instagram file-get-contents instagram-api php-curl


【解决方案1】:

cUrl 总是比 file_get_contents() 更快,我们也在我们的网站上尝试过这个,但最好的方法是 cUrl.that 响应比 file_get_contents() 更快。

如果你设置像'Connection: close'这样的标题但你不能更快地得到响应

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    相关资源
    最近更新 更多