File_get_contents (): php_network_getaddresses: getaddrinfo failed

I am trying to update some values ​​from one server to another using a cron job. I am using file_get_contents ().

The strange thing is that this sometimes happens. One minute it works, another minute it won’t work. I get these two errors:

PHP Warning: file_get_contents (): php_network_getaddresses: getaddrinfo failed: name or service unknown

PHP Warning: file_get_contents (): failed to open stream: php_network_getaddresses: getaddrinfo failed: name or service unknown

and

PHP Warning: file_get_contents (): php_network_getaddresses: getaddrinfo failed: No address associated with the host name

PHP Warning: file_get_contents (): could not open the stream: php_network_getaddresses: getaddrinfo failed: There is no address associated with the host name

I registered on a server that is experiencing this problem. Using ping or traceroute works fine, so I eliminated the problems with DNS. I also added google DNS servers to be sure. A third server that uses the same code does not have this problem, so it looks like a problem on the "calling" end, rather than on the "response". Replacing the hostname IP is not an option for this case.

Does anyone know how to solve this?

+7
php dns file-get-contents
source share
3 answers

In my case, the problem was that Apache gets DNS records from /etc/resolv.conf when it starts. By the time I started my Apache, the network had not yet been installed. Restarting Apache (after setting up the network) solved the problem for me.

I explained this matter in more detail in my blog post http://diogomelo.net/blog/16/Warning-file_get_contents-php_network_getaddresses-getaddrinfo-failed-No-address-associated-with-hostname

+10
source share

It seems that the name lookup does not work while cron is running. I only saw it with names in / etc / hosts, but I did not test the DNS names.

I saw him sending emails on email timeouts and SMTP connections.

I do not know the exact reason, but in my case I received my SMTP code to connect to 127.0.0.1 instead of localhost , and the problem disappeared.

+1
source share

This is due to connection restrictions on the 2nd server, and I believe that you set short time intervals for the cron job. As you know, servers control serial connections from each IP address. You can choose a longer time interval to solve this problem.

0
source share

All Articles