【问题标题】:fsockopen() unable to connect to www.google.com:80fsockopen() 无法连接到 www.google.com:80
【发布时间】:2017-02-21 06:22:40
【问题描述】:

我在使用 fsockopen() 或 file_get_contents() 函数时遇到了一些问题

$test = fsockopen("www.google.com", 80, $errno, $errstr, 30);

还给我

Warning: fsockopen(): unable to connect to www.google.com:80 (Connection timed out) 

注册流套接字传输 tcp、udp、unix、udg、ssl、tls、tlsv1.0、tlsv1.1、tlsv1.2

allow_url_fopen = 开启

我在 php7-fpm + nginx vps 上运行,但无法正常工作..

更新 使 fsockopen 到一个 IP 地址有效...

这是我的 etc/resolv.conf

nameserver 213.133.99.99
nameserver 213.133.100.100
nameserver 213.133.98.98

更新 curl -vvv http://www.google.com 回复

* Hostname was NOT found in DNS cache
*   Trying 2a00:1450:4001:811::2004...
*   Trying 216.58.214.68...
* Connected to www.google.com (216.58.214.68) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: www.google.com
> Accept: */*
>
< HTTP/1.1 302 Found
< Cache-Control: private

谢谢

【问题讨论】:

    标签: php


    【解决方案1】:

    根据您对上一个答案的评论,听起来您的 IP 已被 Google 阻止,或者您的 DNS 设置已损坏。

    当你尝试 curl 时会发生什么:

    $ curl -vvv http://www.google.com/
    

    如果是 DNS 问题,应该可以直接访问 IP:

    $ curl 64.233.162.99
    

    如果都不行,请尝试其他网站,例如:

    $ curl -vvv http://www.stackoverflow.com/
    

    您正在运行什么操作系统和 VPS?

    【讨论】:

    • 这是一个有 3-4 个网站的 Debian... nginx/1.10.1 + PHP 7.0.11-1~dotdeb+8.1
    猜你喜欢
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 2019-08-30
    • 2014-03-10
    • 2018-12-30
    • 2018-07-08
    • 2013-04-23
    相关资源
    最近更新 更多