php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50807 getaddrinfo sporadically fails
Submitted: 2010-01-20 18:20 UTC Modified: 2010-02-03 01:00 UTC
Votes:8
Avg. Score:4.1 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:3 (42.9%)
From: skasun at tucson dot com Assigned:
Status: No Feedback Package: Network related
PHP Version: 5.3.1 OS: OS X Leopard Server
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: skasun at tucson dot com
New email:
PHP Version: OS:

 

 [2010-01-20 18:20 UTC] skasun at tucson dot com
Description:
------------
We keep sporadically getting this error:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in [path to script] on line XX

It has nothing to do with DNS on the machine. I can have dns_get_record return a valid response on the exact same page as that error. It's also not consistent.  getaddrinfo works 90% of the time, but randomly, without any changes to the machine or the scripts, it will give the above error.

Reproduce code:
---------------
$page=file_get_contents("http://google.com");

Expected result:
----------------
The contents of google.com gets put into $page

Actual result:
--------------
90% of the time, we get the expected result.. but then it will start failing and it may take several page reloads for it to start magically working again.

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in [path to script] on line XX

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-20 18:30 UTC] rasmus@php.net
PHP doesn't do anything magic here.  We are simply calling your system's getaddrinfo function.  The code looks like this:

    if ((n = getaddrinfo(host, NULL, &hints, &res))) {
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n));
        }

getaddrinfo() returns 0 on success.  And as you can see from the code, the error is coming from your getaddrinfo() low-level call.  That error message corresponds to an EAI_AGAIN error from the call.  On my system the man page just says:

       EAI_AGAIN
              The name server returned a temporary failure indication.  Try again later.

So, I am not sure how to help you here.  I see nothing wrong with the code as evidenced by the fact that it works most of the time for you.  Can you check the logs of your dns server and see why you might be getting temporary failures there?
 [2010-01-26 04:14 UTC] skasun at tucson dot com
Just a follow up, it is indeed not PHP's fault (thanks Rasmus, your 
response helped us determine the true cause).

We have determined that launching a background process (apache for 
example) from the command line and then logging out will cause OSX to 
flag that process's Context for garbage collection. That will prevent 
that process's children from looking up Mach ports, which will cause 
getaddrinfo to return EAI_AGAIN. Since not all children are GC'd, some 
apache processes work, others fail.

Apparently this affects Leopard and Snow Leopard.  Our fix was as simple 
as running Apache from GNU screen.
 [2010-01-26 04:20 UTC] rasmus@php.net
That sounds really odd.  You are saying that Apache is essentially 
broken on OSX by default.  Interesting.
 [2010-02-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-08-04 13:56 UTC] atiware at gmx dot net
i tested this bug using various php functions (curl_*, fopen, fsockopen, DOMDocument::loadHTMLFile, gethostbyname)
strange is, if everything else fails, gethostbyname returns still a valid address.

i inspected the sources and found that there are two different functions used to get the address of a domain.
./main/network.c uses getaddrinfo or gethostbyname (which one, depens on the system where php is running)

./ext/standard/dns.c uses only gethostbyname

in network.c at line 245:
/* XXX NOT THREAD SAFE (is safe under win32) */
host_info = gethostbyname(host);

means this that the php function gethostbyname (and all function in dns.c) are not thread safe?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 19:01:28 2024 UTC