|  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( "", "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/ on line 24

Warning: fopen("","r") - Bad file descriptor in /var/www/ on line 24
Cannot open URL 

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

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

	fsockopen("", 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);

I get this output:

Error: (0)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-21 21:47 UTC]
Please check that your nameserver is running and setup
correctly.  Check the same with your internet server.
 [2001-07-22 04:45 UTC]
Could you try to comment out the line
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]
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:


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]
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]
If you have IPV6 support enabled, try turning it off,
or vice-versa.
 [2002-04-03 11:34 UTC]
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]
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
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
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("", 80, &$errno, &$errstr, 30);

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

fsockopen("", 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/, 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 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:

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]
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:// 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
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.

 [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://, 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 to /etc/hosts appeared to be a provisoric
 [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 

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:


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
 [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.
 [2014-07-16 22:45 UTC] tino dot spirit at gmail dot com
This is not a PHP Bug !
It's a server misconfiguration

Check out my thread at :

I've shared some of my gathered solutions there.
 [2014-12-17 10:07 UTC] rakeshpatil919 at gmail dot com
i m tryng to get image type by using getimagesize() function from remote network sometimes its working perfect but sometimes its showing 

A PHP Error was encountered

Severity: Warning

Message: getimagesize(): php_network_getaddresses: getaddrinfo failed: Name or service not known
 [2015-09-30 15:24 UTC] piet at ibuildings dot nl
Today I had a problem resolving, I got the following error msg:
php_network_getaddresses: getaddrinfo failed: No address associated with hostname

Using the default Fedora 22 packages:
Apache/2.4.16 (Fedora)
PHP 5.6.13 (cli) (built: Sep  3 2015 12:18:26)

When I started my pc in de morning I had no issues resolving a hostname. Somewhere during the day it went wrong. Restarting Apache solved the problem.

How can be addressed as 'Not a bug'!? It took 1 hour of my time figuring out that a basic PHP function was failing me.
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Wed May 25 01:01:48 2016 UTC