Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
solf
V2EX  ›  Linux

迫不得已,只能发帖求助:用EC2上运行Amazon Linux,PHP的fopen不能解析域名,但CURL等都正常

  •  
  •   solf · Dec 19, 2012 · 6965 views
    This topic created in 5069 days ago, the information mentioned may be changed or developed.
    实在不知道是PHP问题还是Linux问题,所以就发到这里来。入正题:

    背景:
    在EC2上运行Amazon Linux,使用wget和curl均正常。
    编译安装的PHP,ini文件确认已将allow_url_fopen打开,PHP里使用CURL也一切正常。

    问题:
    PHP的函数,包括fopen, file_get_contents, getimagesize,均不能解析域名——连file_get_contents(http://localhost/index.php)都不行,返回空值(不是false);而使用ip地址是没问题——如 file_get_contents(http://127.0.0.1/index.php)

    补充:
    我一开始以为是DNS问题,但其他函数如curl_init后再exec都没有问题,均可正确读取所有网址。也以为是SELINUX问题,发现好像并没有安装SELINUX,/etc下连selinux目录也没有。
    11 replies  •  1970-01-01 08:00:00 +08:00
    saharabear
    saharabear
    Dec 19, 2012
    1
    看一下php.ini里面有没有打开fopen的选项。
    solf
    solf
    OP
    Dec 20, 2012
    2
    @saharabear 都打开了。就是域名不会解析
    kingwkb
    kingwkb
    Dec 20, 2012
    3
    为什么要自己编译呢,Amazon 的yum很好
    BOYPT
    BOYPT
    Dec 20, 2012
    4
    file_get_contents如果有错误会在log里面给warnning的,看看log了什么吧,怎么就说是DNS呢
    solf
    solf
    OP
    Dec 20, 2012
    5
    @BOYPT 没有任何warning或者notice。如果用getimagesize就有read error的warning。 gethostbyname等function都正常
    BOYPT
    BOYPT
    Dec 20, 2012❤️1
    6
    @solf 那应该是其他问题了. Stackoverflow找到个相似的:

    http://stackoverflow.com/questions/4172860/file-get-contents-returns-empty-string

    说是PHP的bug~
    solf
    solf
    OP
    Dec 21, 2012
    7
    @BOYPT 太感谢了。从你提供的贴中找到线索。原来是curl问题
    BOYPT
    BOYPT
    Dec 24, 2012
    8
    @solf 也是去除--with-curlwrapper 重新编译?
    solf
    solf
    OP
    Dec 24, 2012
    9
    @BOYPT 对。
    BOYPT
    BOYPT
    Dec 25, 2012
    10
    @solf 嗯 解决了问题最好把重点信息在这里重复一次,以便关注者了解到。
    solf
    solf
    OP
    Dec 27, 2012
    11
    @BOYPT 谢谢提醒。

    解决办法是编译的时候将 ‘--with-curlwrapper’ 去掉,因为这个参数还在实验阶段。去掉后fopen就会使用http的wrapper,而不是用curl的wrapper。

    我是在以下链接找到解决办法
    http://weizhifeng.net/wrong-with-curlwrappers.html
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2280 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:44 · PVG 19:44 · LAX 03:44 · JFK 06:44
    ♥ Do have faith in what you're doing.