V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
liuxurong
V2EX  ›  PHP

Ubuntu13 VPS PHP DNS 失灵!file_get_contents() cURL 为空白。

  •  
  •   liuxurong · Mar 25, 2014 · 5486 views
    This topic created in 4416 days ago, the information mentioned may be changed or developed.
    VPS上的DNS是Google的DNS,ping没有问题。

    但是PHP用域名file_get_contents和curl打开网页就返回空白了(直接用相关IP地址就可以。)

    这是什么原因吗?!我连防火墙都关了。

    这个问题困扰我6个小时了!找了好多资料。
    Supplement 1  ·  Mar 25, 2014
    谢谢各位,由ubuntu13换成centos6.5问题居然自动解决了. XDDDDDDDDD

    至今还不知道是啥原因.

    程序是业余搞搞哈.
    21 replies    1970-01-01 08:00:00 +08:00
    liuxurong
        1
    liuxurong  
    OP
       Mar 25, 2014
    file_get_contents("http://www.baidu.com") //返回空白

    file_get_contents("220.181.111.86") //百度IP正常返回
    inee
        2
    inee  
       Mar 25, 2014
    google dns 已经被折磨阵亡
    webjin
        3
    webjin  
       Mar 25, 2014 via Android
    机房白名单
    liuxurong
        4
    liuxurong  
    OP
       Mar 25, 2014
    @webjin 你们可以详细一点吗?

    @inee
    liuxurong
        5
    liuxurong  
    OP
       Mar 25, 2014
    @inee
    @webjin

    补充一下,用Python Requests做同样的事情是没问题的。
    11138
        6
    11138  
       Mar 25, 2014   ❤️ 1
    最大可能是DNS的问题。
    如果是这样,你只有自己指定一下IP(HTTP headers)来访问了。
    liuxurong
        7
    liuxurong  
    OP
       Mar 25, 2014
    @11138 会不会是PHP的问题?
    11138
        8
    11138  
       Mar 25, 2014   ❤️ 1
    file_get_contents请求的域名如果解析不了你得到的结果就是空白。
    你说是PHP的问题也是,说是DNS的问题也行,看你的理解。
    如果你坚持用file_get_contents,那你只能用我上面说的办法测试一下是否可行。
    11138
        9
    11138  
       Mar 25, 2014   ❤️ 1
    还有,你有没有看过PHP的日志???
    liuxurong
        10
    liuxurong  
    OP
       Mar 25, 2014
    11138
        11
    11138  
       Mar 25, 2014   ❤️ 1
    你到底有没有看我对你说的?
    1,日志!
    2,构造HTTP headers测试一下能不能访问
    liuxurong
        12
    liuxurong  
    OP
       Mar 25, 2014
    @11138
    1, 我好像没开日志 XDDDDDDD error_reporting(E_ALL); 头部这个行不行?
    2, 构造了,不行。
    liuxurong
        13
    liuxurong  
    OP
       Mar 25, 2014
    @11138 error_reporting(E_ALL); 这个是没反馈的。
    11138
        14
    11138  
       Mar 25, 2014   ❤️ 1
    1,先把日志弄出来。日志很重要,至少第一时间把问题告诉你,你看你已经浪费多少时间在找问题身上,你连问题在哪里还不知道。
    2,把你测试的代码放上来看看。
    liuxurong
        15
    liuxurong  
    OP
       Mar 25, 2014
    @11138 谢谢提点,我决定先重装系统,我疑是ubuntu的问题
    11138
        16
    11138  
       Mar 25, 2014
    别动不动就重装系统。都跟你说了,记录一下PHP的日志就知道是什么原因了。
    alexrezit
        17
    alexrezit  
       Mar 25, 2014 via iPhone
    你还是转行吧.
    leadfast
        18
    leadfast  
       Mar 25, 2014
    楼上的不要如此打击撸主嘛
    cute
        19
    cute  
       Mar 25, 2014
    @liuxurong

    gethostbyname('baidu.com');

    能工作吗?

    If name resolution fails with apache2, mod_chroot and php5, add
    LoadFile /lib/libnss_dns.so.2
    to the mod_chroot config.
    zts1993
        20
    zts1993  
       Mar 25, 2014
    试试末尾加 / 试试
    liuxurong
        21
    liuxurong  
    OP
       Mar 25, 2014
    @cute
    @zts1993
    @alexrezit
    @leadfast
    @11138

    谢谢各位,由ubuntu13换成centos6.5问题居然自动解决了. XDDDDDDDDD

    至今还不知道是啥原因.

    程序是业余搞搞哈.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5061 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    ♥ Do have faith in what you're doing.