PHP 错误:php_network_getaddresses:getaddrinfo 失败:(同时从其他站点获取信息。)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6275535/
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 error: php_network_getaddresses: getaddrinfo failed: (while getting information from other site.)
提问by Imran Khan
Trying to get information from an external source, I'm receiving the following error:
尝试从外部来源获取信息时,我收到以下错误:
Warning: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in line #...
警告:php_network_getaddresses:getaddrinfo 失败:第 # 行中的名称解析暂时失败...
Yesterday everything was fine, so what happened to this script, which is not working and gives me the error above? Any solution or hint to solve this problem?
昨天一切都很好,那么这个脚本怎么了,它不起作用并给我上面的错误?任何解决方案或提示来解决这个问题?
$uri = "http://api.hostip.info/?ip=$ip&position=true";
$dom->load($uri);
I also tried by converting DNS to IP but then I get the warning: failed to open
我也尝试将 DNS 转换为 IP,但随后收到警告: failed to open
$uri = "174.129.200.54/?ip=$ip&position=true";
I tried to remove the http
but am still getting the above error.
我试图删除http
但仍然收到上述错误。
回答by Dmitri Gudkov
It's because you can't resolve the host name Maybe DNS problems, host is unreachable...
那是因为你无法解析主机名 可能是DNS问题,主机不可达...
try to use IP address instead of host name... ping this host name... nslookup it...
尝试使用 IP 地址而不是主机名... ping 这个主机名... nslookup 它...
回答by Anand
In the following httpd.conf
file, configure the ServerName
properly.
在以下httpd.conf
文件中,ServerName
正确配置。
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf
Like below:
像下面这样:
ServerName 127.0.0.1:80
or
或者
ServerName sitename
This resolved similar issue I was facing.
这解决了我面临的类似问题。
回答by crx4
In my case(my machine is ubuntu 16), I append /etc/resolvconf/resolv.conf.d/base
file by adding below ns lines.
在我的情况下(我的机器是 ubuntu 16),我/etc/resolvconf/resolv.conf.d/base
通过添加以下 ns 行来附加文件。
nameserver 8.8.8.8
nameserver 4.2.2.1
nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888
then run the update script,
然后运行更新脚本,
resolvconf -u
回答by Steve Mayne
I would imagine that the caching DNS servers you're using aren't behaving properly (or the DNS server for the domain you're resolving isn't working properly). You can try to fix the former possibility.
我认为您使用的缓存 DNS 服务器运行不正常(或者您正在解析的域的 DNS 服务器工作不正常)。您可以尝试修复前一种可能性。
Do you have at least 2 name servers registered on your network adapter? You could always swap your computer over to use a different caching DNS server to rule this out. Try Google's:
您的网络适配器上是否至少注册了 2 个名称服务器?您可以随时更换您的计算机以使用不同的缓存 DNS 服务器来排除这种情况。试试谷歌的:
8.8.8.8
8.8.4.4
回答by symcbean
If you can discount transient outages on the remote server you are trying to connect to, then that just leaves the local network config as a problem.
如果您可以减少尝试连接的远程服务器上的暂时中断,那么这只会使本地网络配置成为一个问题。
Using the IP address instead of the hostname is only going to work for the default domain on the remote host.
使用 IP 地址而不是主机名仅适用于远程主机上的默认域。
What happens when you try using www.google.com (or its IP address)? If you stil can't connect, then its something to do with the network between your server and the outside world.
当您尝试使用 www.google.com(或其 IP 地址)时会发生什么?如果您仍然无法连接,那么它与您的服务器和外部世界之间的网络有关。
回答by Diwakar Padmaraja
Although this is a old thread, I have come across the same error recently while running nslookup in CentOS 7 and google search led me to some of the discussions in SO including this one. However, adding the nameservers entries to /etc/resolv.conf alone did not help as the nameserver values in resolv.conf were overwritten by the NetworkManager with the default DNS nameservers that are in the eth profile associated to the ethernet IP config.
虽然这是一个旧线程,但我最近在 CentOS 7 中运行 nslookup 时遇到了同样的错误,谷歌搜索导致我在 SO 中进行了一些讨论,包括这个。但是,单独将名称服务器条目添加到 /etc/resolv.conf 并没有帮助,因为 resolv.conf 中的名称服务器值被 NetworkManager 用默认 DNS 名称服务器覆盖,这些名称服务器位于与以太网 IP 配置关联的 eth 配置文件中。
As mentioned by @m-canvar, set the following entries in /etc/resolv.conf
正如@m-canvar 所提到的,在 /etc/resolv.conf 中设置以下条目
search yourdomain.com
nameserver 8.8.8.8
nameserver 4.2.2.1
nameserver 8.8.4.4
To prevent overwriting these entries by NetworkManager, there are two two approaches:
为了防止 NetworkManager 覆盖这些条目,有两种方法:
Option 1: Either set NM_CONTROLLED=no in the eth profile associated to the IPv4/IPv6 profile.
选项 1:在与 IPv4/IPv6 配置文件关联的 eth 配置文件中设置 NM_CONTROLLED=no。
Option 2: Disable NetworkManager service from running.
选项 2:禁止运行 NetworkManager 服务。
chkconfig NetworkManager off
service NetworkManager stop
More details can be referred in my post about this error and solution.
更多细节可以参考我关于这个错误和解决方案的帖子。
回答by Mendy
Although I didn't use this exact function I got this same error.
虽然我没有使用这个确切的函数,但我得到了同样的错误。
In my case I just had to remove the protocol.
在我的情况下,我只需要删除协议。
Instead of $uri = "http://api.hostip.info/?ip=$ip&position=true";
代替 $uri = "http://api.hostip.info/?ip=$ip&position=true";
Use $uri = "api.hostip.info/?ip=$ip&position=true";
用 $uri = "api.hostip.info/?ip=$ip&position=true";
And it worked fine afterwards
然后它工作得很好
回答by Vladimir Kornea
In my case this was being issued by wp cli
, and the problem was that I didn't have php7.3-curl
installed. Fixed with: apt-get install -y --quiet php7.3-curl
在我的情况下,这是由 发布的wp cli
,问题是我没有php7.3-curl
安装。固定:apt-get install -y --quiet php7.3-curl
回答by idara inyang
I think that you should try replacing php7.3-curl with api.hostip.info/?ip=$ip&position=true . Hope this helps
我认为你应该尝试用 api.hostip.info/?ip=$ip&position=true 替换 php7.3-curl 。希望这可以帮助
回答by Sarkar
I faced this issue, while connecting DB, the variable to connect to db was not defined.
我遇到了这个问题,在连接数据库时,未定义连接到数据库的变量。
Cause:php
tried to connect to the db with undefined variable for db host(localhost/127.0.0.1/... any other ip or domain) but failed to trace the domain.
原因:php
尝试使用未定义变量的数据库主机(localhost/127.0.0.1/...任何其他 ip 或域)连接到数据库,但未能跟踪域。
Solution:Make sure the db host
is properly defined.
解决方案:确保db host
正确定义了 。