Scott Klarr Jr
Temporary failure in name resolution in PHP script
Warning: main() [function.main]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/username/public_html/index.php on line 777
This error popped on one of my clients website and it got me stumped. Through SSH, the DNS seemed to work fine. I could run host domain.com, curl, wget, etc - but when php would try to load the url, it failed with the above error. I tried setting different DNS resolver servers, restarted services, and checked for config errors but could not find the source of this problem. So I then turned to google.
I searched quite extensively and could not find a real concrete explanation or one-time-fix solution. However, there is a rather duct-tape-like fix that will work if you are needing to open up predetermined URLs (for example, paypal.com for payment IPN verification). If you are needing to open up dynamic URLs, such as ones submitted by users, then this is not a good fix.
To apply the fix, you simple open up /etc/hosts and add a line for each domain you are trying to access. In my case, I needed to add:
216.113.188.64 www.paypal.com
To determine the IP address of the domain you need to add, you can either ping it, or run host domain.com from a linux machine to resolve an IP address.



Jan Oct 04, 2008
Any chance you found a solution for this by time? I bumped into the same problem. Worst is, i am on dedicated box and I have no idea what's wrong, all DNS settings seem to be fine.
scott Oct 04, 2008
Jan: All I can recommend is to contact your host and let them know of the error your getting. Maybe even show them this post in case it can help them get it resolved.
Son Nguyen Feb 06, 2009
I got this issue with my development MacBook MacOS X. Still don't know what causes it other than restarting Apache. It will be gone for a while and then comes back.