dongmanzui8486 2010-02-08 17:43
浏览 133

PHP5 - 未处于交互模式时无法解析主机名

I'm working with an OS X 10.6 Server running Apache2 / PHP5 and having a problem with PHP not resolving hostnames when 'fopen()' tries to retrieve a file from a remote server. When run in interactive mode on the command line 'fopen()' works perfectly. However, when run through the web it will always fail with the error:

failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

I'm at a loss in finding the source of this problem: 'fopen()' works on the web when given an IP address instead of a hostname; 'gethostbyname()' also fails when run on the web (it doesn't error, it just returns whatever hostname it was given to resolve) but also works fine when run in interactive mode. The only exception seems to be 'dns_get_record()' which works fine when run on the web or in interactive mode.

I've been trying to find DNS problems on the server but dig, nslookup, and ping all work and "scutil -r" says the remote server is reachable with the current DNS settings. Any ideas on where the problem might be?

  • 写回答

6条回答 默认 最新

  • dtk31564 2010-02-08 17:46
    关注

    You must set properly the allow_url_fopen value of your php.ini.

    http://ar.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

    Consider the CLI uses a different php.ini that the webserver (I assume you are using Apache).

    Another option may be you are not including libnss_dns

    Try adding to your httpd configuration (correct path as needed for you system):

    LoadFile /lib/libnss_dns.so
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致