php - 最近在 ubuntu 16.04 上使用 php 7 到同一服务器的完整 url 的 file_get_contents 非常慢

标签 php ubuntu nginx file-get-contents php-7

会不会与以下有关:

https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1674733

只是一个想法?可能不会,因为最终,它确实有效。

这曾经非常快,现在需要 7 秒到 26 秒来制作一个小图像,并且也存储在本地。

“好吧,只需将代码更改为不通过 h​​ttp 进行”,我宁愿不重写我用来解决突然冒出来的问题的库。如果我在本地开发机器上本地执行相同的调用,则需要一瞬间。
myapp/public/caup_laravel/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php
代码:

   $options = array(
        'http' => array(
            'method'=>"GET",
            'header'=>"Accept-language: en\r\n".
            "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n"
      )
    );

    $context  = stream_context_create($options);
    if ($data = @file_get_contents($url, false, $context)) { //VERY slow call
        return $this->initFromBinary($data);
    }

网址的示例是:

http://dev.causepick.org/caup_api/uploads/causes/52/cropped-436535-a42b2.jpg

通过浏览器访问图像是即时的,例如如果我在地址栏中输入 url

最佳答案

我收到了来自我的服务器提供商的 digitalocean 的回复

We've received reports of a DNS outage affecting users that utilize Google's DNS servers, which is the default on all of our images. This droplet is in the affected IP range, so it is likely related to the issue.

Can you try using OpenDNS's servers, 208.67.222.222 and 208.67.220.220, as your primary or backup nameservers? This should resolve the issue you are facing. You can do this temporarily (it will persist until your next reboot) by editing /etc/resolv.conf to look like this:


nameserver 208.67.222.222  
nameserver 208.67.220.220 

So far everything points to this being an issue on Google's end, affecting UDP-based DNS queries from our 192.241.128.0/17 range. Eventually, queries can fall back to TCP, which allows them to succeed, but it takes several seconds explaining the slowness you're seeing. We've seen Google rate-limit or block selective IP ranges before, and it was very difficult to pin down. We've already reached out to Google and we are awaiting a response and resolution.



这行得通

关于php - 最近在 ubuntu 16.04 上使用 php 7 到同一服务器的完整 url 的 file_get_contents 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43053872/

相关文章:

php - MySQLi PHP -> 使用获取数组时 LEFT JOIN 返回 Null

git - .gitignore 文件不会显示在 Cloud9 文件面板中

node.js - 使用 Nginx 时 socket.io 出现 CORS 错误

php - 在本地主机上使用带有 xampp 的 PHP 获取数据并将其插入 MySQL 数据库

php - 显示来自表连接 mysql 的某些 id

mysql - 无法通过 Ubuntu 服务器连接到远程 MySQL 数据库

python - 无法在ubuntu上运行python3

nginx - 为 E2E 测试配置 nginx-ingress

nginx - nginx自定义错误配置,引用字符串与文件

php - 如何使用 php 和 curl 登录 instagram 并获取 sessionid?