up vote 5 down vote favorite
1
share [g+] share [fb]

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

link|improve this question

Is the script failing all the time? Or just occasionally? – MikeyB May 31 '09 at 3:29
Fails every time. – GeoffreyF67 May 31 '09 at 3: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
feedback

5 Answers

up vote 6 down vote accepted

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.

link|improve this answer
Restart did the trick! – GeoffreyF67 May 31 '09 at 4:10
2  
Yes, but how long before the next restart is due? I would look further and find the root cause of the problem. – Xerxes May 31 '09 at 5:06
feedback

I just experienced the same error and

service httpd restart

did the trick...

link|improve this answer
feedback
% 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?

link|improve this answer
feedback

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

link|improve this answer
feedback

Wow I was having the same issue, but apparently

service httpd restart

is the solution... but I still doesn't understand what causes this...

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.