PDA

View Full Version : Fopen To Remote Addresses Failing- Server Problem?


gimp
03-30-2005, 03:06 PM
Hi, I'm trying to run a php script I wrote up, and I keep getting errors which say:

Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/../getItems.php on line 313
...
Warning: fopen(http://webservices.amazon.com/onca/xml?...): failed to open stream: Success in /home/.../getItems.php on line 313


I get this error about 4 out of every 5 times I try to load the page. It's really quite annoying, and I don't know what could be going wrong, other than perhaps there's a server problem.

This started happening to me over the weekend, but then it went away for a couple of days (Mon, Tues), and now it is happening again. I've tried running my script on another server with another provider and it works just fine.

Line 313 is pretty simple and it looks like this:

if ($fp=fopen($queryURL,'r')) {

where $queryURL is a string such as "http://webservices.amazon.com/onca/xml?...Attributes"- basically, I'm making an outgoing call to the amazon webservices protocol.

Does anyone have any idea what might be going wrong???
Is this a known problem, or is anyone else having similar problems?

Thanks

gimp
03-30-2005, 03:33 PM
I tried writing a simple script to duplicate the problem, and I get the same error:

<?php

echo '<p>Hello World</p>';
$queryURL = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=1CCZZCPADSNHMYZB44G2&AssociateTag=slackometer-20&Operation=ItemSearch&SearchIndex=Tools&BrowseNode=228013&ItemPage=1&Sort=salesrank&ResponseGroup=Small,Images,OfferSummary,ItemAttrib utes";

if ($fp=fopen($queryURL,'r')) {
while ($data = fread($fp, 4096)) {
echo $data;
}
}
?>

Output:

Hello World

Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/slacko00/domains/slackometer.com/public_html/test2.php on line 6

Warning: fopen(http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=1CCZZCPADSNHMYZB44G2&AssociateTag=slackometer-20&Operation=ItemSearch&SearchIndex=Tools&BrowseNode=228013&ItemPage=1&Sort=salesrank&ResponseGroup=Small,Images,OfferSummary,ItemAttrib utes): failed to open stream: Success in /home/slacko00/domains/slackometer.com/public_html/test2.php on line 6

gimp
03-30-2005, 03:35 PM
Try it out for yourself here (http://www.slackometer.com/test2.php).

Works everytime on my other server.

eugene
03-30-2005, 10:53 PM
Originally posted by gimp@Mar 30 2005, 01:35 PM
Try it out for yourself here (http://www.slackometer.com/test2.php).

Works everytime on my other server.
Quoted post

Can you open the file by using the IP address instead of the domain name? 207.171.163.96

gimp
03-31-2005, 02:42 PM
Thanks Eugene,
Actually, I received the same tip on another forum, and so I tried it out:

original script using domain name (http://www.slackometer.com/test2.php)

script using hand-coded IP (http://www.slackometer.com/test4.php)

As you can see, the first link works less than half of the time, whereas the 2nd link works 100% of the time.

Do you have an account w/ hostpc, eugene? If you do, would you mind copy/pasting the first script and running it off of your account, just so I can confirm that I'm not insane and this happens for other people as well? The paranoid part of me is worrying that I screwed up some dns, mx, cname, or some other config setting I don't understand.

The people on the other forum I've posted on say it's definitely a server-side problem and that there's something wrong w/ the host's php setup.

I really don't want to resort to hard-coding IP addresses, and if the problem just disappears (like it did for a couple of days), I want some reassurance that the problem won't just come back again randomly.

Thanks!

eugene
03-31-2005, 07:21 PM
The problem occurs on many hosts and can prove to be quite annoying. It is a result of problems with DNS cache and requests. Although frustrating and perhaps disturbing to use an IP address, you should notice a performance gain when using the IP address directly instead of having to rely on the server performing a DNS query.

If it were the case that the server you were trying to reach was on a shared host, you would be unable to rely on just using the IP.

My own advice and preference is to cache data that is not likely to change much or rapidly, this will cut down on overhead needed by your script.