...

View Full Version : fopen() headache



pixencom
05-20-2008, 03:07 PM
I am trying to run the following code:


<?php

$url = "http://mydomain.com/stats/tracker.php?page=TESTENTRY"; // I have removed the domain for demo purposes but the domain exists, is resolved etc etc.

$handle = fopen ($url, "r");
$test = fgets($handle);
fclose($handle);

?>

When I do I get the error:


Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/user4873/public_html/test.php on line 5

allow_url_fopen is set to On in php.ini. Any ideas on why this is happening? The same script works on a different server and loads fine with no errors.

PLEASE someone help with this one. Thank you!

bcarl314
05-20-2008, 03:17 PM
A quick google search (http://www.google.com/search?q=Warning%3A+fopen%28%29+%5Bfunction.fopen%5D%3A+php_network_getaddresses%3A+getaddrinfo+fail ed%3A&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a) yields this from the php.net manual:



If you're having problems with fopen("url...") but you can run 'host url' in a shell window and get the correct lookup, here's why...

This has had me banging my head against it all day - finally I found the answer buried in the bug reports, but figured it should really be more prominent!

The problem happens when you're on an ADSL line with DHCP (like our office)... When the ADSL modem renews the DHCP lease, you can also switch DNS servers, which confuses apache (and hence PHP) - meaning that you can't look up hosts from within PHP, even though you *can* from the commandline.... The short-term solution is to restart apache.

You'll get "php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in ..." messages as symptoms. Restart apache, and they're gone :-)

Simon


I find it very helpful to simply copy / paste the warning message into google to find results to problems like this.

oesxyl
05-20-2008, 03:25 PM
just in case echo the url, could be a typo somewhere in http:// part, and check the php version, :)

if you don't find anything try to compare the configuration of both servers, with what you said until now it must work.

regards

pixencom
05-20-2008, 03:33 PM
A quick google search (http://www.google.com/search?q=Warning&#37;3A+fopen%28%29+%5Bfunction.fopen%5D%3A+php_network_getaddresses%3A+getaddrinfo+fail ed%3A&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a) yields this from the php.net manual:



I find it very helpful to simply copy / paste the warning message into google to find results to problems like this.

Thanks for the replies. I actually did google search this, I guess I did look hard enough. All what I read was make sure that its set to "On" in php.ini. I am on a shared server right now, what do I tell my webhost to get them to fix this?

Also just wanted to point out (dont know if it makes a difference) my error states:


php_network_getaddresses: getaddrinfo failed: Name or service not known


php_network_getaddresses: getaddrinfo failed: Temporary failure in name

Like I said, dont know if its the same thing.

o0DarkEvil0o
05-20-2008, 08:09 PM
why do you use file_get_contents() instead?

pixencom
05-21-2008, 01:27 AM
I get the same error with that:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/user4873/public_html/test.php on line 5

Inigoesdr
05-21-2008, 03:20 AM
That error usually means that your server has a DNS configuration error or similar problem. Notify your host and see what they can do about it.

pixencom
05-21-2008, 07:07 AM
Thank you for your replies. I submitted a ticket on hostgator and linked them here and they took care of the problem. No more errors! Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum