Ubuntu13 VPS PHP DNS 失灵!file_get_contents() cURL 为空白。 - V2EX
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 5184 次点击
    这是一个创建于 4243 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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     Solana     5062 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 09:21 PVG 17:21 LAX 01:21 JFK 04:21
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86