Temporary failure in name resolution in PHP script

Posted On Feb 03, 2008 at 5:25 am

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.

This topic has the following tags: