Page 1 of 1

php_network_getaddresses: getaddrinfo failed

PostPosted: 10. July 2009 11:52
by indapoint
Hello

I have installed XAMPP on my Linux server (Fedora 11) and some of the specific PHP functions are not working like file() and curl lib. When I try to use these functions it gives me an error like

Code: Select all
file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in ….


On my php.ini allow_url_fopen set to on

Host file and networking is ok on server, if we try to ping any domain (e.g. http://www.google.com) from shell/command seems working fine. However PHP is not able to access same domain.
Please help

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 10. July 2009 12:18
by Nobbie
Probably a firewall is blocking the Apache process or similar.

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 10. July 2009 13:12
by indapoint
I have deactivated firewall before to solve this but it did not work

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 10. July 2009 13:24
by glitzi85
What's the output of an nslookup on the shell? Could you also try to execute the same nslookup command via the PHP-Function passthru(). Also check the entries in /etc/resolv.conf.

glitzi

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 14. July 2009 12:43
by indapoint
Hi

here is the output from shell
Code: Select all
$ nslookup http://www.google.com
Server:         192.168.0.2
Address:        192.168.0.2#53

Non-authoritative answer:
http://www.google.com  canonical name = http://www.l.google.com.
http://www.l.google.com        canonical name = www-notmumbai.l.google.com.
Name:   www-notmumbai.l.google.com
Address: 64.233.189.99
Name:   www-notmumbai.l.google.com
Address: 64.233.189.104
Name:   www-notmumbai.l.google.com
Address: 64.233.189.147


Here is output from PHP passthru
Code: Select all
Server: 192.168.0.2 Address: 192.168.0.2#53 Non-authoritative answer: http://www.google.com canonical name = http://www.l.google.com. http://www.l.google.com canonical name = www-notmumbai.l.google.com. Name: www-notmumbai.l.google.com Address: 64.233.189.147 Name: www-notmumbai.l.google.com Address: 64.233.189.99 Name: www-notmumbai.l.google.com Address: 64.233.189.104


Does this give any idea ?

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 14. July 2009 20:37
by glitzi85
What did you mean with:
However PHP is not able to access same domain.

?

And what domain do you try to open with file()?

glitzi

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 15. July 2009 10:36
by indapoint
This means that I can ping any domain from command line on same server but while I try to access same domain by PHP, using file() or CURL it gives me an error as I posted.

It does not work with any domain and gives an error as I posted here (Above).

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 15. July 2009 12:46
by glitzi85
OK, now it is clear what you mean.

The problem is, that this error message can be caused by a lot of things. Mostly when the target is not reachable, but that doesn't sound like your problem, as you get the error with all domains. Other common problem is the DNS system. To verify this, could you please post the file /etc/resolv.conf. In this file you should find some IPs. Could you please execute this command with every IP:

Code: Select all
dig @IP google.com

alternative, if you do not have dig installed run this command:
Code: Select all
nslookup google.com IP


glitzi

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 15. July 2009 13:05
by indapoint
Hello I just have follwoing details on my file /etc/resolv.conf
Code: Select all
# Generated by NetworkManager
nameserver 192.168.0.1
nameserver 192.168.0.2
 


As I wrote before, everything is working OK with all users on Linux, I mean Internet is working fine, emails are working fine on Linux machine, it is only issue when PHP tries to access Internet

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 15. July 2009 13:31
by glitzi85
indapoint wrote:Hello I just have follwoing details on my file /etc/resolv.conf
Code: Select all
# Generated by NetworkManager
nameserver 192.168.0.1
nameserver 192.168.0.2
 

Could you try the command i posted with both IPs please.

indapoint wrote:As I wrote before, everything is working OK with all users on Linux, I mean Internet is working fine, emails are working fine on Linux machine, it is only issue when PHP tries to access Internet

Your Linux normally tries the first entry in the List, if there is no response from the DNS server, then it tries the next and so on. PHP only checks the first one, if it gets no response, you get the error message
Code: Select all
file() [function.file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in ….

So the first entry in this file MUST be an valid DNS Server!

glitzi

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 16. July 2009 08:18
by indapoint
Code: Select all
[root@xxxxxx~]# nslookup 192.168.0.1
Server:         192.168.0.2
Address:        192.168.0.2#53

** server can't find 1.0.168.192.in-addr.arpa.: NXDOMAIN

[root@xxxxx~]# nslookup 192.168.0.2
Server:         192.168.0.2
Address:        192.168.0.2#53

** server can't find 2.0.168.192.in-addr.arpa.: NXDOMAIN

I think there is something wrong here , what does this
Code: Select all
** server can't find 2.0.168.192.in-addr.arpa.: NXDOMAIN
mean and what is
Code: Select all
2.0.168.192 and 1.0.168.192
?

Thanks

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 16. July 2009 09:26
by indapoint
SOLVED
Hey
Finally I could solve the issue by changing my DNS entry, initially I put my router IP which was local and then I changed to live IPs (The one provided by my ISP) and it worked.

However, question still remains unanswered, If there was a problem in DNS then why it was working from shell ? It was only PHP which had an issue with that.

Thanks !!

Re: php_network_getaddresses: getaddrinfo failed

PostPosted: 16. July 2009 14:14
by glitzi85
indapoint wrote:and what is
Code: Select all
2.0.168.192 and 1.0.168.192

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

I am not absolutely sure what the problem here is. I am also not really sure how nslookup exactly works, but i think the PHP function throws much faster an error.

glitzi