52

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 #...

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

$uri = "174.129.200.54/?ip=$ip&position=true";

I tried to remove the http but am still getting the above error.

halfpastfour.am
  • 5,764
  • 3
  • 44
  • 61
Imran Khan
  • 2,373
  • 2
  • 22
  • 35
  • @Cold Hawaiian: Ok, i am updating my question. – Imran Khan Jun 08 '11 at 07:34
  • Can you open the link right in your browser? If no, that is not a PHP problem. Hostip.info could have you blocked for accessing their site for misuse or whatever. – sanmai Jun 08 '11 at 08:26
  • On my computer this command works all right: `curl "http://api.hostip.info/?ip=\`curl whatismyip.org\`&position=true"` – sanmai Jun 08 '11 at 08:29
  • Yes, here also work fine.. but in script not working. – Imran Khan Jun 08 '11 at 08:55
  • The answer is to correct your `/etc/hosts`. Make sure the url points to where it should (usually localhost). – tread Jul 18 '16 at 08:50
  • adding an IP address for URL wont always work out fine since many websites usually have a proxy server in front of the url to have dynamic ip – cyberrspiritt Sep 06 '21 at 04:49

13 Answers13

48

It's because you can't resolve the host name Maybe DNS problems, host is unreachable...

try to use IP address instead of host name... ping this host name... nslookup it...

Dmitri Gudkov
  • 2,093
  • 16
  • 15
12

In the following httpd.conf file, configure the ServerName properly.

/etc/httpd/conf/httpd.conf

Like below:

ServerName 127.0.0.1:80

or

ServerName sitename

This resolved similar issue I was facing.

Prashant Pokhriyal
  • 3,727
  • 4
  • 28
  • 40
Anand
  • 121
  • 2
  • I have NO IDEA why this makes a difference but it solved my issue as well. I would periodically get DNS failures and setting ServerName fixed the issue. – David Apr 08 '16 at 05:50
8

In my case(my machine is ubuntu 16), I append /etc/resolvconf/resolv.conf.d/base file by adding below ns lines.

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
mcanvar
  • 465
  • 6
  • 13
  • 1
    @AbdulAzizAlBasyir Because of dns resolution, script try to recognize the address. You can find further info from [here.](http://manpages.ubuntu.com/manpages/zesty/man5/resolv.conf.5.html). – mcanvar Dec 01 '17 at 08:13
5

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.

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:

8.8.8.8
8.8.4.4
Steve Mayne
  • 22,285
  • 4
  • 49
  • 49
1

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.

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.

symcbean
  • 47,736
  • 6
  • 59
  • 94
0

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.

As mentioned by @m-canvar, set the following entries in /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:

Option 1: Either set NM_CONTROLLED=no in the eth profile associated to the IPv4/IPv6 profile.

Option 2: Disable NetworkManager service from running.

chkconfig NetworkManager off
service NetworkManager stop

More details can be referred in my post about this error and solution.

0

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";

Use $uri = "api.hostip.info/?ip=$ip&position=true";

And it worked fine afterwards

Mendy
  • 7,612
  • 5
  • 28
  • 42
0

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

Val Kornea
  • 4,469
  • 3
  • 40
  • 41
0

I think that you should try replacing php7.3-curl with api.hostip.info/?ip=$ip&position=true . Hope this helps

0

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.

Solution: Make sure the db host is properly defined.

Rohit Sharma
  • 1,271
  • 5
  • 19
  • 37
Sarkar
  • 123
  • 1
  • 7
0

I faced a similar issue on Docker for Ubuntu. It's a DNS issue. You will have to add Google Public DNS Settings into your network. Instruction for adding those settings is OS dependant. In my case, I was using Ubuntu so I added via network manager. Visit this site for more info.

enter image description here

0

The resolvers are having issues. The resolvers are specified in the /etc/resolv.conf file and are set based on the network configuration scripts on the Droplet. These are populated by the initial deployment configuration cloud-init system.

Solution 1:
You can add nameserver in this file: /etc/resolv.conf

nameserver 127.0.0.53
options edns0

Solution 2:
We need to specify a remote DNS server as our global, system-wide DNS server. We can do this in this file : /etc/systemd/resolved.conf

[Resolve]
DNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844

And Then reload configuration and restart services:

sudo systemctl daemon-reload
sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved

After Storage Full I have freed up space, No Install commands are working like apt-get update, and also PHP file_get_contents() and curl() also not working. The 2nd Solution worked for me on the ubuntu Server.

ajmirani
  • 366
  • 3
  • 8
0

if you using docker containers then add socket in MySQL configuration, it solved my issue unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock