11

I've got a script in PHP that's been running fine for months. It recently stopped working.

This script connects to gmail to send out an email to my customers.

Recently, I started getting this error when I run the script:

The SMTP connection failed to start [tls://smtp.gmail.com:465]: 
fsockopen returned Error Number 0 and Error String 'php_network_getaddresses: 
getaddrinfo failed: Temporary failure in name resolution'

Keep in mind, this was with zero code changes.

I've looked at my resolv.conf and it appears to be ok:

nameserver 208.67.222.222

I can ping gmail.com:

# ping smtp.gmail.com
PING gmail-smtp-msa.l.google.com (74.125.93.111) 56(84) bytes of data.
64 bytes from qw-in-f111.google.com (74.125.93.111): icmp_seq=1 ttl=247 time=26.7 ms  

I can connect via lynx to google and other sites with no problem.

I've logged into my gmail account with no problems (no captcha there either).

I am at wits end. Anyone have any ideas?

G-Man

GeoffreyF67
  • 497
  • 2
  • 7
  • 14
  • Is the script failing *all* the time? Or just occasionally? – MikeyB May 31 '09 at 03:29
  • Fails every time. – GeoffreyF67 May 31 '09 at 03:37
  • I encountered similar issue with my daemon written in C which performs periodic TCP reconnections. At some point getaddrinfo() suddenly started to return the error. When I looked at the server, no DNS requests were being sent, and adding the required entry into /etc/hosts did not help. Sure, restart helps but as Xerxes rightfully noted, this is not the real solution. Initially I thought that the problem was caused by missing freeaddrinfo() call but I failed to reproduce it with a test application. Anyway, I've added proper cleanup calls to the daemon and going to monitor it closely. – Linulin Dec 21 '09 at 11:54

6 Answers6

14

PHP is having trouble accessing either /etc/hosts or /etc/resolv.conf: there's a long standing issue in PHP related to this specific error. The fix is to try restarting Apache or whatever is invoking PHP, or to make sure /etc/hosts and /etc/resolv.conf are readable by what's invoking PHP.

6

I just experienced the same error and

service httpd restart

did the trick...

2
% dig @208.67.222.222 smtp.gmail.com +short
gmail-smtp-msa.l.google.com.
209.85.201.109
209.85.201.111
%

Now, try using Xdebug to see where the problem is exactly....

<?php
xdebug_start_trace('/tmp/lookup-trace.log');
$ip = gethostbyname('smtp.gmail.com');
xdebug_stop_trace();
die($IP);
?>

Anything good in the logs?

khosrow
  • 4,163
  • 3
  • 27
  • 33
1

Add debugging code before that line to make sure that the script can resolve it correctly.

Matt Simmons
  • 20,396
  • 10
  • 68
  • 116
0

I have had this fault today, however it occurred after a specific event which makes me think that i may have found the cause.

Due to some network equipment trouble, i actually rebooted by server and when it came back up, there was an incorrect network connection in the cabling, effectively meaning no DNS server was available.

in the meantime this php function was called and after this it never worked again until i restarted httpd.

I think the bug may relate to a network failure (where the DNS is not only not available, but unreachable, ie wrong subnet) and when the network subsequently recovers this function does not look for the DNS again.

This thead was a few years ago, maybe this bug is now fixed in PHP?

Charlie
  • 11
0

I was having the following issue while upgrading magento 2 to the latest version, so I suspect it is the issue with the php configuration.

The "https://repo.magento.com/packages.json" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 
failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Resolved it by restarting the xampp through command.

sudo /opt/lampp/lampp/stop
sudo /opt/lampp/lampp/start

Then tried the composer update command again and it worked like a charm.

Umar Yousaf
  • 101
  • 1