php file() [function.file]: php_network_getaddresses: getaddrinfo failed: 名称解析暂时失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2880563/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:00:54  来源:igfitidea点击:

file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

phpchat

提问by Sachin

I got the following error when I get contents from file("http://www.otherdomain.com").

当我从文件(“ http://www.otherdomain.com”)中获取内容时出现以下错误。

file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

The domain server is linux.

域服务器是linux。

How to resolve this problem?

如何解决这个问题?

回答by Shahriyar Imanov

Quoting:

引用:

If you're having problems with fopen("url...") but you can run 'host url' in a shell window and get the correct lookup, here's why...

This has had me banging my head against it all day - finally I found the answer buried in the bug reports, but figured it should really be more prominent!

The problem happens when you're on an ADSL line with DHCP (like our office)... When the ADSL modem renews the DHCP lease, you can also switch DNS servers, which confuses apache (and hence PHP) - meaning that you can't look up hosts from within PHP, even though you canfrom the commandline.... The short-term solution is to restart apache.

You'll get "php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in ..." messages as symptoms. Restart apache, and they're gone :-)

Simon

如果您在使用 fopen("url...") 时遇到问题,但您可以在 shell 窗口中运行 'host url' 并获得正确的查找,这就是为什么...

这让我一整天都在头疼——最后我找到了隐藏在错误报告中的答案,但我认为它真的应该更加突出!

当您使用带有 DHCP 的 ADSL 线路(例如我们的办公室)时,问题就会发生……当 ADSL 调制解调器续订 DHCP 租约时,您还可以切换 DNS 服务器,这会混淆 apache(以及 PHP)——这意味着您可以即使您可以从命令行中查找主机,也不要从 PHP 中查找主机......短期解决方案是重新启动 apache。

您将收到“php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in ...”消息作为症状。重新启动apache,它们就消失了:-)

西蒙

Comment by Simon at php.net

Simon 在 php.net 的评论

回答by Mihai Iorga

make sure that website can be reached from you server. also make sure that you are using has a proper DNS server setup.

确保可以从您的服务器访问该网站。还要确保您使用的 DNS 服务器设置正确。

if you are sure that website is working ... try modifying the /etc/hosts file and add the website's IP for test purposes, then try to figure out why it doesn't solve the domain.

如果您确定该网站正在运行...尝试修改 /etc/hosts 文件并添加网站的 IP 以进行测试,然后尝试找出它无法解决域的原因。

回答by favo

The Domain can not be resolved to it's IP address.

域无法解析为其 IP 地址。

If you have your DNS running local, try restarting it. If not, check your DNS or add a different server to /etc/resolve.conf (i.e. nameserver 8.8.8.8).

如果您的 DNS 在本地运行,请尝试重新启动它。如果没有,请检查您的 DNS 或将不同的服务器添加到 /etc/resolve.conf(即名称服务器 8.8.8.8)。

You can also add the domain as a static entry in your hosts file:

您还可以将域添加为 hosts 文件中的静态条目:

On your linux server add the DNS information to your /etc/hosts file using:

在您的 linux 服务器上,使用以下命令将 DNS 信息添加到您的 /etc/hosts 文件中:

echo '127.0.0.1 www.otherdomain.com' >> /etc/hosts

echo '127.0.0.1 www.otherdomain.com' >> /etc/hosts

…where 127.0.0.1 is the IP address of your website and www.otherdomain.com the domain name your using.

...其中 127.0.0.1 是您网站的 IP 地址,www.otherdomain.com 是您使用的域名。

You can find the IP address of any domain using nslookup, i.e

您可以使用 nslookup 查找任何域的 IP 地址,即

nslookup www.otherdomain.com

nslookup www.otherdomain.com

回答by Ahmed Rashid

I was running into this issue with CiviCRMgeocoding! Restarting Apache like Shehi recommended fixed the problem.

我在使用CiviCRM地理编码时遇到了这个问题!像 Shehi 建议的那样重新启动 Apache 解决了这个问题。