PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #11058 php_network_getaddresses: getaddrinfo failed
Submitted:23 May 2001 11:58am UTC Modified: 8 Apr 2009 5:37am UTC
From:pat at mail dot rit dot edu Assigned to:
Status:Bogus Category:Network related
Version:4.0.6 OS:OpenBSD 2.6
View/Vote Developer Edit Submission

[23 May 2001 11:58am 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)

[21 Jul 2001 9:47pm UTC] andy@php.net
Please check that your nameserver is running and setup
correctly.  Check the same with your internet server.
[22 Jul 2001 4:45am 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.
[3 Aug 2001 10:53pm UTC] sniper@php.net
What's the status for this?? 
[7 Aug 2001 12:56pm 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.
[9 Aug 2001 3:02pm 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.
[7 Dec 2001 9:12am UTC] sterling@php.net
its a problem with your operating system setup, not PHP.
[7 Feb 2002 3:31am 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.
[3 Apr 2002 11:19am 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.
[3 Apr 2002 11:32am UTC] wez@php.net
If you have IPV6 support enabled, try turning it off,
or vice-versa.
[3 Apr 2002 11:34am UTC] wez@php.net
In your OS config that is.
[3 Apr 2002 2:03pm UTC] g dot almasi at gigcity dot com
Is this setting in /etc/rc.config?
[3 Apr 2002 2:18pm 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.
[3 Apr 2002 3:58pm 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.
[3 Apr 2002 4:20pm 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.
[3 Apr 2002 4:27pm 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>
[4 Jun 2003 10:08am 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
[12 Feb 2004 9:15pm 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_ge
taddresses%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 :)
[4 May 2004 2:35pm 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).
[13 May 2004 12:32am 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 :(
[13 May 2004 12:34am 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...
[26 May 2004 9:45pm 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...)
[10 Jun 2004 2:40pm 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.
[30 Jun 2004 6:17pm 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 :(
...
[14 Jul 2004 10:29pm 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
[16 Aug 2004 1:40am UTC] hachem at phptunisia dot com
restart the bind
[21 Aug 2004 2:38pm 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 :)
[27 Sep 2004 7:06pm UTC] rowaldru at gpi dot com
I am currently on 4.3.8. Has this issue been addressed and fixed in
5.0.1?
[8 Apr 2009 5:37am UTC] avenger@php.net
I have this problem on RHEL5 too.
My sloved is "chmod 644 /etc/hosts"
Simple,but useful for me.

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC