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: 2017-03-23 17: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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pat at mail dot rit dot edu
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [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 :

http://serverfault.com/questions/612992/nginx-and-php-cant-resolve-hostname-and-make-connection-with-fqdn

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 google.com, 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.
 [2017-03-23 08:48 UTC] kostello at gmail dot com
I have just encountered this issue twice on two separate virtual machines over the past 24 hours! These VMs are stable, the uptime was about one week for the first, about twelve hours for the second, when the errors occurred. They both run Ubuntu 14.04 LTS, nginx 1.8, PHP-FPM. More specifically, the first VM runs PHP 7.0.15-1+deb.sury.org~trusty+1, and the second one runs PHP 5.5.9-1ubuntu4.21. Here is the error message I get with file_get_contents($url)

>> Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /script.php on line 276
>> Warning: file_get_contents(http://www.******.com/history.php): failed to open stream: php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /script.php on line 276)

NB: using CURL did not work either but did not return any data nor did it trigger any error message. However I assume that it is for the same reason.

Both times, I inspected the configuration: DNS resolvers, permissions on /etc/hosts, on /etc/resolv.conf, and other things, all good. Furthermore, no DNS issues to report when using "wget" or "svn update" or any other network tool - it was really just PHP. To rule out a possible error in my own PHP scripts, I created a simple "test.php" file with one line: file_get_contents('http://www.google.com') and the error still occurred.

The only way I could got rid of the problem in both cases was doing a "service php-fpm restart". As the issue was critical, I had to quickly proceed with the restart and I didn't have time to investigate further. How can I make sure this doesn't happen again?
 [2017-03-23 08:56 UTC] spam2 at rhsoft dot net
did you guys who are affected install updates on your machines which replaced from webserver/php loaded libraries without re-starting the webserver? updating "nss" without hard restart httpd was the only time in the past decade where is saw similar issues - hence don't appyl autoupdates blindly and restart services with orphaned filehandles - especially services which are forking or have multiple threads
 [2017-03-23 16:33 UTC] chilieu dot me at gmail dot com
This happened to our server again in 24hrs
Our is running Ubuntu 16.04 LTS, nginx, PHP-FPM, PHP 7.0.15-1+deb.sury.org~trusty+1

when I was trying to use file_get_contents to get estimation shipping fee from ups
the only way I can fix it is restart php
 [2017-03-23 17:08 UTC] spam2 at rhsoft dot net
And i still bet it is not a problem on the php side - disable response rate limiting on your nameserver, switch to. A different or setup your own resolver

I had a similar issue because I thought php at least would cache the answers at least within a loop doing file_get_contents() over a large url-array all within the same domain 

So when your page has such code and some bot is running wild you produce the dns request for each and every pagecall and so easily exceed response limits 

When you use the curl extension identical dns queries are at least cached within the same request
 [2017-03-23 17:37 UTC] heiglandreas@php.net
This is an issue on the Ubuntu-side! They rolled out a faulty update. https://launchpad.net/ubuntu/+source/glibc/2.23-0ubuntu7

This is NOT a PHP-Issue!
 [2017-03-24 03:45 UTC] kostello at gmail dot com
To heiglandreas: I have tried to update my system (Ubuntu 14.04 LTS) and there is no mention of such an update, unfortunately. What's more, the two VMs that encountered the error were not updated for several days prior to the problem. And finally, the name resolution error occurred only within PHP - other attempts to replicate the problem outside of PHP failed. I am not saying you are wrong, on the contrary you are in a much better place than myself to know what's happening, I am just providing additional elements for you to consider. It shall be noted that I haven't encountered the error again since the last time I restarted PHP-FPM on either VM.

To spam2 at rhsoft dot net: I do not believe this applies to my case. The uptime on the first VM was several days, with few daily HTTP requests (about 1000-2000) and very few of these required name resolution - the file_get_contents($url) instruction is used in only specific part of my application. The second VM had about 12 hours uptime when the error occurred and had received less than 50 HTTP requests. I shall add that the two VMs are on two completely separate network, in different countries, and once again outside of PHP everything was working perfectly fine. Also, no, I did not update server components before the errors occurred. I did not do anything in particular. I wish my bash_history file had time stamps to show you I am talking in good faith.
 [2017-03-24 08:06 UTC] anael dot favre at gmail dot com
I have exactly the same problem as you kostello.

I have 3 virtual machines and one hos having this problem since 2-3 days in production. All are Ubuntu 16.04.2, php7.0-fpm, nginx running production servers.

It is really annoying as it also break external php debugger tools (like sentry, bugsnag) so we are completely blind when its happen (and have to check the logs).

I first think about a downtime of the DNS server, and then php cache it and return bad values until a php-fpm restart.

My servers are running at OVH (france) and you ?
 [2017-03-24 08:13 UTC] kostello at gmail dot com
Replying to: anael dot favre at gmail dot com

My two VMs are hosted as follows

1) first one is hosted on a Hyper-V 2012 server, uses two DNS servers on the LAN, plus two fallbacks via Google DNS. The building is situated in Singapore and has excellent connectivity (1gbps fiber). No problems were detected with the local DNS servers at the time of the problem.

2) second one is hosted on a VMWare vSphere server, uses two DNS servers on the LAN, and one fallback via Google DNS. I am not at liberty to disclose the location but the connectivity is good and it has a very large fiber. No problems were detected with the local DNS servers at the time of the problem.
 [2017-03-24 08:35 UTC] spam2 at rhsoft dot net
> problem since 2-3 days in production. All are Ubuntu 16.04.2

do you read what others say - https://bugs.php.net/bug.php?id=74287
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC