PHP php_network_getaddresses:getaddrinfo 失败:没有这样的主机是已知的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8210099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP php_network_getaddresses: getaddrinfo failed: No such host is known
提问by Richard
I am having DNS issues with a certain target domain. I am using fopen()
(but same issue with other functions) to retreive an image, but I get this error:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No such host is known
我遇到了某个目标域的 DNS 问题。我正在使用fopen()
(但与其他功能相同的问题)来检索图像,但出现此错误:
Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No such host is known
I am able to ping or nslookup the domain from the command prompt, but for some reason php throws this error. When I try fopen('http://www.google.com', r);
or other domains, all goes fine. But above mentioned domain simply won't resolve with PHP. I have flushed the DNS, restarted Apache, but still no luck..
我可以从命令提示符 ping 或 nslookup 域,但由于某种原因,php 会抛出此错误。当我尝试fopen('http://www.google.com', r);
或其他域时,一切顺利。但是上面提到的域根本无法用 PHP 解析。我已经刷新了 DNS,重新启动了 Apache,但仍然没有运气..
I have tried with:
我试过:
- Windows 7, Apache 2.2 PHP 5.3.6
- Windows server 2008r2, Apache 2.2 PHP 5.3.6
- Windows 7,Apache 2.2 PHP 5.3.6
- Windows 服务器 2008r2,Apache 2.2 PHP 5.3.6
What can cause this single domain to not resolve?
什么会导致这个单一域无法解析?
采纳答案by Ivan Buttinoni
IMO it's the different way to resolve a name from the OS and PHP.
IMO 这是从操作系统和 PHP 解析名称的不同方式。
Try:
尝试:
echo gethostbyname("host.name.tld");
and
和
var_export (dns_get_record ( "host.name.tld") );
or
或者
$dns=array("8.8.8.8","8.8.4.4");
var_export (dns_get_record ( "host.name.tld" , DNS_ALL , $dns ));
You should found some DNS/resolver error.
您应该发现一些 DNS/解析器错误。
回答by anil
Your "localhost" cannot resolve the name www.google.com, which means your machine doesn't/can't reach a valid dns server.
您的“本地主机”无法解析名称 www.google.com,这意味着您的机器无法/无法访问有效的 dns 服务器。
Try ping google.com on the console of that machine to verify this.
尝试在该机器的控制台上 ping google.com 以验证这一点。
回答by Mostafa Lavaei
It is more flexible to use curl
instead of fopen
and file_get_content
for opening a webpage.
它是使用更加灵活curl
,而不是fopen
和file_get_content
打开的网页。
回答by bonger
A weird thing I found was that the environment variable SYSTEMROOT
must be set otherwise getaddrinfo()
will fail on Windows 10.
我发现一个奇怪的事情是SYSTEMROOT
必须设置环境变量,否则getaddrinfo()
将在 Windows 10 上失败。
回答by Szektor
Your target domain might refuse to send you information.This can work as a filter based on browser agent or any other header information. This is a defenseagainst bots, crawlers or any unwanted applications.
您的目标域可能会拒绝向您发送信息。这可以作为基于浏览器代理或任何其他标头信息的过滤器。这是对机器人、爬虫或任何不需要的应用程序的防御。
回答by nyxee
What had caused this error on my side was the following line
在我这边导致这个错误的是以下行
include_once dirname(__FILE__) . './Config.php';
I managed to realize it was the culprit when i added the lines:
当我添加以下行时,我设法意识到这是罪魁祸首:
//error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
//ini_set('display_errors', 1);
to all my php files.
到我所有的 php 文件。
To solve the path issue
i canged the offending line to:
为了解决path issue
我将违规行更改为:
include_once dirname(__FILE__) . '/Config.php';