【问题标题】:PHP file_get_contents() Suddenly Stopped WorkingPHP file_get_contents() 突然停止工作
【发布时间】:2018-01-11 18:21:16
【问题描述】:

我的 PHP file_get_contents() 突然停止工作。我没有做任何更改,它之前运行良好。但是从今天早上开始,它会超时,我的服务器会抛出错误的网关错误。

我使用 curl 通过命令提示符检查了同样的事情,它工作正常。 php有问题。

【问题讨论】:

    标签: php curl nginx


    【解决方案1】:

    我通过强制 file_get_contents() 使用 IPV4 解决了这个问题。似乎它正在尝试通过没有互联网连接的 IPV6。

        $options = array(
            'socket' => array(
                          'bindto' => '0:0'
                        ),
           'http' => array(
           'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
           'method'  => 'POST',
           'content' => http_build_query($data)
          )
        );
    
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
    

    谢谢。

    【讨论】:

    • 谢谢!这正是我需要与谷歌验证码交谈的内容:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    • 2021-02-01
    • 2016-12-29
    • 2018-05-09
    • 2015-12-07
    • 2015-08-23
    相关资源
    最近更新 更多