V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
liuxurong
V2EX  ›  PHP

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

  •  
  •   liuxurong · 2014-03-25 00:24:10 +08:00 · 4630 次点击
    这是一个创建于 3684 天前的主题,其中的信息可能已经有所发展或是发生改变。
    VPS上的DNS是Google的DNS,ping没有问题。

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

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

    这个问题困扰我6个小时了!找了好多资料。
    第 1 条附言  ·  2014-03-25 14:01:34 +08:00
    谢谢各位,由ubuntu13换成centos6.5问题居然自动解决了. XDDDDDDDDD

    至今还不知道是啥原因.

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

    file_get_contents("220.181.111.86") //百度IP正常返回
    inee
        2
    inee  
       2014-03-25 00:31:45 +08:00
    google dns 已经被折磨阵亡
    webjin
        3
    webjin  
       2014-03-25 00:41:50 +08:00 via Android
    机房白名单
    liuxurong
        4
    liuxurong  
    OP
       2014-03-25 00:52:35 +08:00
    @webjin 你们可以详细一点吗?

    @inee
    liuxurong
        5
    liuxurong  
    OP
       2014-03-25 00:54:03 +08:00
    @inee
    @webjin

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

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

    至今还不知道是啥原因.

    程序是业余搞搞哈.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3318 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.