PHP5 - 无法解析主机名时在交互式方式 [英] PHP5 - Fails to resolve hostnames when not in interactive mode

查看:327
本文介绍了PHP5 - 无法解析主机名时在交互式方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与运行的Apache2 / PHP5的OS X 10.6服务器工作,具有当'fopen()函数试图从远程服务器检索文件PHP不是主机名解析问题。当以交互方式在命令行中运行'fopen()函数完美的作品。然而,当通过网络运行它总是会失败,出现错误:

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

我在寻找这个问题的根源损失:给定IP地址而不是主机名时)的fopen(作品在网络上;当在网络上运行'的gethostbyname()也会失败(它没有错误,它只是返回的任何主机它被赋予解决),但在交互模式下运行时也能正常工作。唯一的例外似乎是'dns_get_record()时,在网络上或在交互模式下运行的正常工作。

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.

我一直试图找到服务器上的DNS问题,但是挖,nslookup将和ping所有的工作和scutil -r说:在远程服务器可达当前的DNS设置。对存在问题可能是任何想法?

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?

推荐答案

您必须正确设置你的php.ini的allow_url_fopen选项值。

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

HTTP://ar.php。净/手动/ EN / filesystem.configuration.php#ini.allow-URL-的fopen

考虑CLI使用不同的php.ini的网络服务器(我假设你使用的是Apache)。

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

另一个选择可能你是不包括libnss_dns

Another option may be you are not including libnss_dns

尝试添加到您的httpd配置文件(根据需要为您的系统正确的路径):

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

LoadFile /lib/libnss_dns.so

这篇关于PHP5 - 无法解析主机名时在交互式方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆