liuxurong
V2EX  ›  PHP

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

  •  
  •   liuxurong · Mar 25, 2014 · 6048 views
    This topic created in 4609 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
    liuxurong
    OP
    Mar 25, 2014
    1
    file_get_contents("http://www.baidu.com") //返回空白

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

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

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

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

    至今还不知道是啥原因.

    程序是业余搞搞哈.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5464 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 03:38 · PVG 11:38 · LAX 19:38 · JFK 22:38
    ♥ Do have faith in what you're doing.