php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11058 php_network_getaddresses: getaddrinfo failed
Submitted: 2001-05-23 11:58 UTC Modified: 2009-04-08 05:37 UTC
From: pat at mail dot rit dot edu Assigned:
Status: Not a bug Package: Network related
PHP Version: 4.0.6 OS: OpenBSD 2.6
Private report: No CVE-ID:
 [2001-05-23 11:58 UTC] pat at mail dot rit dot edu
I've seen this issue posted here a few times, and I think my problem is similar to Bug id #7880.

fopen(), fsockopen(), and file() will not work with URL or IP address parameters. include() has the same issue. I believe it has something to do with getaddrinfo.

Before upgrading to PHP4, I was running 3.0.16 and all of these functions were working perfectly with URL parameters. 

My configure script looks like this:

./configure  --with-apache=/usr/temp/apache_1.3.19 --with-mysql=/usr/local --enable-track-vars --with-xml --with-openssl=/usr/local/ssl

My php.ini DOES contain the line "allow_url_fopen = On"

The fopen() script looks like this:

	$fd = fopen( "http://www.php.net/", "r" );
	if( !$fd )
	{
		echo "Cannot open URL";
	} else {
		while ( !feof( $fd ) ) {
			$buffer = fgets( $fd, 4096 );
			echo $buffer;
		}
		fclose ( $fd );
	}

and produces this output:

Warning: php_network_getaddresses: getaddrinfo failed: name or service is not known in /var/www/patrickhaney.com/www/weather/test.php on line 24

Warning: fopen("http://www.php.net/","r") - Bad file descriptor in /var/www/patrickhaney.com/www/weather/test.php on line 24
Cannot open URL 

and yes, I can resolve php.net to 208.247.106.187. Using the IP address in place of the hostname produces the same output.

If I use the fsockopen() function with this script:

	fsockopen("http://www.php.net/", 80, &$errno, &$errstr, 30);
	if(!$fp) {
		echo "Error: $errstr ($errno)<br>\n";
	} else {
		fputs($fp,"GET / HTTP/1.0\n\n");
		while(!feof($fp)) {
			echo fgets($fp,128);
		}
		fclose($fp);
	}

I get this output:

Error: (0)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-21 21:47 UTC] andy@php.net
Please check that your nameserver is running and setup
correctly.  Check the same with your internet server.
 [2001-07-22 04:45 UTC] venaas@php.net
Could you try to comment out the line
#define HAVE_GETADDRINFO 1
in main/php_config.h and rebuild without doing configure?
Does it work then? There are some broken getaddrinfo()
implementations out there, but I would be surprised if
there were problems with OpenBSD in general. Might be
something wrong with your resolver library.

OTH, you also have a problem with fsockopen() and that
uses the old gethostbyname() I think, so it seems to be resolving in general.
 [2001-08-03 22:53 UTC] sniper@php.net
What's the status for this?? 

 [2001-08-07 12:56 UTC] pat at mail dot rit dot edu
Still having the same issue with 4.0.6 now. I'll try and recompile without the GETADDRINFO line and see what happens.
 [2001-08-09 15:02 UTC] pat at mail dot rit dot edu
Still not resolved.

I commented out the line:

#define HAVE_GETADDRINFO 1

from my main/php_config.h file, did a make, then a make install. Recompiled Apache, stopped and started the server, and still have the same errors.

I also tried changing the value to 0, and did the same to #define LIBRESOLV 1 to see if that was the problem (for some reason there are 2 identical lines with LIBRESOLV in my php_config.h file). Nothing.

Any ideas? This was working perfectly before upgrading to PHP4, and I haven't touched the box except to upgrade Apache and install OpenSSL.
 [2001-12-07 09:12 UTC] sterling@php.net
its a problem with your operating system setup, not PHP.
 [2002-02-07 03:31 UTC] navajo at slip dot net
Im currently running into the same issue with the base 
install of SUSE 7.3, fopen(), fsockopen(), and file() also 
to not work with URL's or an ip address.
 [2002-04-03 11:19 UTC] g dot almasi at gigcity dot com
I'm running SuSE 7.3 and I'm having this exact problem too. Has anyone found a solution? I see the above comment about the problem being in the system configuration and I'm wondering if someone could elaborate on that. Thanks.
 [2002-04-03 11:32 UTC] wez@php.net
If you have IPV6 support enabled, try turning it off,
or vice-versa.
 [2002-04-03 11:34 UTC] wez@php.net
In your OS config that is.
 [2002-04-03 14:03 UTC] g dot almasi at gigcity dot com
Is this setting in /etc/rc.config?
 [2002-04-03 14:18 UTC] g dot almasi at gigcity dot com
So I just tried changing a line in /etc/modules.conf:
- From "alias net-pf-10 off"
- To "alias net-pf-10 ipv6"
I rebooted the box and I still had this problem happening.
 [2002-04-03 15:58 UTC] g dot almasi at gigcity dot com
another note: I have root to another box (it serves about 20 sites to the web) that is also running PHP 4.0.6 and php_network_getaddresses works fine. Does this function require a nameserver? My SuSE 7.3 box is a development machine on my LAN, so I just use proxies to get to it with a browser. Getting DNS, BIND, and DHCP to work was beyond me when I set it up (still is, actually). So I just use a proxy setting for browsers while I build sites.
 [2002-04-03 16:20 UTC] wez@php.net
And that is the cause of the problem (and the reason that
this report is set to bogus).
You need to tell your SuSE box how to resolve the addresses; the SuSE yast tool should let you set the nameserver in it's network configuration.
I can't help you any further here, and this is not the place to discuss this further.  I'd suggest looking at the SuSE support database for this: it's bound to be a FAQ.
 [2002-04-03 16:27 UTC] g dot almasi at gigcity dot com
Well you can tell I had nothing to do today but beat my head against a wall. But I found a solution!

I added my target site to /etc/hosts and restarted apache, and now I can include a page in that target site from a different site.

It's Miller Time! <psht, glug glug glug>
 [2003-06-04 10:08 UTC] fcartegnie dot at dot free dot dot dot fr at null dot null
Okay. I identified the problem.
When apache starts, php or apache gets dns servers entry
from /etc/resolv.conf
You're using a dialup connection and when logging in, your dns servers have been added at this later moment.
So there's a problem with apache or php to get informed that the content of resolv.conf has been updated.
Confirmed for PHP 4.3.1/apache_1.3.27 so.
Temporary solution is just to reload apache doing a apachectl stop/start
 [2004-02-12 21:15 UTC] cosas at minovela dot com
hello,
my php is PHP Version 4.3.4
i've exatctly the same problem. my server isn't conected by dialup, and i got ever the message
"php_network_getaddresses: getaddrinfo failed"
when i use this line:
fsockopen ("dummy_ip", 25, &$errno, &$errstr, 10)

it didn't occurs with older versions of php.
this IS NOT a server problem, is a problem of PHP, you only need tho make a search at google
http://www.google.es/search?hl=es&ie=UTF-8&oe=UTF-8&q=php+php_network_getaddresses%3A+getaddrinfo+failed&meta=
target "php_network_getaddresses: getaddrinfo failed"
and see results, a lot of people get the same errors.

i hope you found a solution for this :)
 [2004-05-04 14:35 UTC] jeppe at bundsgaard dot net
I guess it is connected to the server - the problem occurs on some, but not all the servers running php4.3 that I am using. Anyway it would be nice with a solution that solves the problem independent of the servers - or that tells exactly what is to be done with the server (I know, this is not the place for such a request - but I don't know where to turn to).
 [2004-05-13 00:32 UTC] cosas at minovela dot com
so nobody give us a solution? 
i can't upgrade to latest version if i want to use fsockopen :(
 [2004-05-13 00:34 UTC] cosas at minovela dot com
i've just installed redhat 9, then the latest version of mysql, php and apache, and i got the error when i tried to run my scripts...
 [2004-05-26 21:45 UTC] jpipes1 at columbus dot rr dot com
We have this darn error occur once every few months; our site relies heavily on fopen's to URL resources on our own servers (to separate templates out...), and I have run into these darn errors with absolutely no help from anyone on any forums.  This error is NOT fixed.  It has to do with something that changed from 4.0.16 to 4.3.4 on Apache 1.3.27 running RedHat 9 too.  Please somebody look into this problem.  

Errors only happen once out of every, say, 20 times, and it always issues the getaddrinfo failed warnings.  Then, the warnings start to happen more and more frequently, on code that has been unchanged in months.  Finally, a restart clears it and we go on for a few months til another restart.

I'm not a C programmer or a Linux guru and I wouldn't know where to start with debugging this stuff, but if someone could take a look at it, it would be helpful.  Navigating around these bug indexes is driving me nuts...

Sounds like some sort of memory leak or something (i.e. the warnings happening after quite some time, then more frequently until a restart...)
 [2004-06-10 14:40 UTC] austinputman at hotmail dot com
I had the same problem as pat at mail dot rit dot edu using fsockopen().

He/she uses:

fsockopen("http://www.php.net/", 80, &$errno, &$errstr, 30);

But you shouldn't use 'http://' in the server name part. So use this instead.

fsockopen("www.php.net", 80, &$errno, &$errstr, 30);

Maybe this will not solve everybodies problem, but it sure solved mine.
 [2004-06-30 18:17 UTC] webmaster at hg-carstyling dot de
i have that problem, too, on 4 machines running RH9, FC1 and FC2. I spend some whole days to solve it, but cannot get the basic of this problem.

On 1 machine i have serveral virt. domains, were i enter the hostnames of 2 domains in /etc/hosts, what results in a fix on one domain, another domain on the same machine was not affected and the error stays as bevor.

I Tryed out, to fix my /var/named/my.stupid.zone, were i found a missconfiguration by redhat-config-bind. I fix the config, checked my nameserver out and hes runnin fine with no errors, but the getadress error stays as bevor and was not affected. I am not really sure, if my dns is perfectly configured, but i get no errors there and funcionality is given, expecting the getadress error by php.

Over that, i cannot see anybody, who has full fixed this problem , so its a discussion worth, but where ?!

I thing, it makes sense, if the Developers, that does or maintain the filesocket functions of php, has a deeper look in this Problem, even if its not php based, but they will have a clear overview, of what happened and maybe they can give us a hint. What about the sockets ?

I thing, it is any incompatibility btw. named and the network classes of php, especaially php mail and file network structures or classes, maybe sockets ?!

On RH8 there are no such errors. In any case, this costs lotsa time :( ...
 [2004-07-14 22:29 UTC] neil dot giarratana at lucidus dot net
Don't know if this helps at all but on RH9, if I do a "service network restart", all is well again and I don't get that error anymore. Beats the heck out of restarting the whole server
 [2004-08-16 01:40 UTC] hachem at phptunisia dot com
restart the bind
 [2004-08-21 14:38 UTC] webmaster at hg-carstyling dot de
ages later, i found a solution, what solves it for me here.
the problem seems to base on the name resolution for the remote machine.

a typical error while opening a remote file was:
----
 Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carstyling/public_html/newnuke/modules/WebMail/pop3.php on line 70

Warning: fsockopen(): unable to connect to mx.freenet.de:110 in /home/carstyling/public_html/newnuke/modules/WebMail/pop3.php on line 70
----
i tryed to reconfigure my named configuration, without any result, to fix this.
the problem was solved by adding the following line to my /etc/hosts:

194.97.55.147      mx.freenet.de

i have to do this for any remote machine i like to open files on. 
this is NOT the basic of that problem, but patches arround that. i was not able, to tell my named, to resolv that adress to that ip, so i have to enter that in /etc/hosts .

it seems, the problem is the name-resolution domain to ip, as it was discribed already here and on other sources before.

over that, it is not a problem of all your php-scripts, you`ve written and were the error comes. just enter the unknown machine to your hosts file and all went fine.

i tryed many different configurations of my bind, but was not able, to resolve other top level domains within a full qualified domain name so i feel to say its a bug in bind by isc, but this can also be a security relatet problem.

i am open for mail and requests and i am very interrested on the basic solution.

regardz :)
 [2004-09-27 19:06 UTC] rowaldru at gpi dot com
I am currently on 4.3.8. Has this issue been addressed and fixed in 5.0.1?
 [2009-04-08 05:37 UTC] avenger@php.net
I have this problem on RHEL5 too.
My sloved is "chmod 644 /etc/hosts"
Simple,but useful for me.
 [2010-03-25 06:28 UTC] cha0s at therealcha0s dot net
Still present in 5.3.
 [2010-05-26 23:27 UTC] pipra133 at yahoo dot com
I am having the same problem .. I am using XAMPP 2.5 version ... it did work for me on the last version ....

I am using the youtube API to receive youtube videos ... 

there is a major change in my case 

Message: Unable to Connect to tcp://gdata.youtube.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: No such host is known. 

the return says it tries with TCP rather then http , but my actual stack trace says it is HTTP . 

#0 C:\xampp\php\PEAR\Zend\Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'http://gdata.yo...', Array, NULL, NULL, NULL)

Does anyone have a clue what is wrong ???
 [2010-06-02 15:53 UTC] elynets at gmail dot com
Hello,
I`ve got the same problem on my server while tried to execute some of my scripts.
The only solution that works fine for me is to disable firewall.
When firewall is disabled I get no errors. 
In the firewall settings all traffic allowed on ports 80 and 53.
 [2010-07-19 12:58 UTC] office at hermannseib dot com
My solution:
Check whether PHP may read /etc/resolv.conf.
First, do a

  ls -la /etc/resolv.conf

and if it says something like this

-rw-r----- 1 root root <size> <date> /etc/resolv.conf

(i.e, NOT readable to anyone but root and the members of group root, which normally means a highly elitist bunch :-), 
then issue the following command as root:

  chmod a+r /etc/resolv.conf

This cured the pesky "getaddrinfo failed" for me.
 [2011-01-06 13:44 UTC] bostjan at a2o dot si
I was experiencing the same problem because the $host variable had some additional spaces at the end. Check with var_dump() and remove invalid characters if any are found.

b.
 [2011-01-10 15:29 UTC] zlisiecki at gmail dot com
I have the same problem on SuSE, apache with php 5.3.3. I am calling fsockopen with 
tls://smtp.gmail.com, 465 and for me it seems php possibly considers tls as wrong
characters in this place and the resolver cannot resolv the address. Adding a
proper line with an IP of smtp.gmail.com to /etc/hosts appeared to be a provisoric
solution.
 [2011-10-11 11:59 UTC] fakefur at gmail dot com
i am having this same problem with PHP 5.3.8 on Arch Linux ... for me it is 
manifesting in the IMAP_OPEN function

the call works if i use an IP Address (but the certificate files so it is not a 
solution for me)

it also works if i do the call from the PHP CLI module (ie, not running in 
apache)

for now i have had to add an entry in my hosts file but obviously this is not a 
good long term solution
 [2012-06-08 13:12 UTC] jono at foodnotblogs dot com
Confirmed this is a problem in my Php 5.3.13 install. With the following line:

file_get_contents("www.google.com");

If I run it in the command line, it works fine. If I run it through apache I get the getaddrinfo failed error.

I am using Arch Linux, Kernel 3.3.7. My temporary work around is to do a full stop and start of Apache. Restarting the service does not solve the problem.
 [2013-04-17 11:28 UTC] frolow at mail dot ru
rb - descriptor
By HelpSet.ru
 [2014-04-10 09:05 UTC] federico dot puntoni at trackset dot com
Still present on 5.3.28

Put the address on /etc/hosts and resolve.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 03:02:42 2014 UTC