fopen extremely slow




I've written a PHP script which grabs data from a webpage to store on my webserver. This script works for fine except for one particular url where is takes around 3-5 minutes to execute (on occasions it times out).

The code which is causing the delay is:

$remotefilehandle = fopen($remotefile,"r")

where $remotefile is ""

If you put this url in a browser, the page displays in a couple of seconds, so why does fopen() take up to 5 minutes?
My script is here...

And the URL its trying to open is:
I may be a newbie, but why do all other url's i open using this script take 2-3 SECONDS, and this particular url take 5 MINUTES!!!!

This does not make sense.
Yes, exactly!

The script works, and the fact that it takes so long is not a major problem, because it is a scheduled script that runs every 20 minutes on the webserver, but i would like to know why it takes so long.
I haven't tried it myself, and not sure if this is the answer, but...

on the romote server that contains the page your trying to open, is the allow_url_fopen option enabled? says it will stop some pages from being opened with fopen if this property is not enabled on their server.

Not sure if it's the answer, but is worth check out perhaps.

good luck.
I used the following code:

$fp = fopen("","r");
while(!feof($fp)) {
$buffer = fgets($fp,4096);
echo $buffer;

The page to it is:

the problem may be within the rest of your code perhaps?
I've commented out the rest of my script to confirm that the fopen is responsible for the 5 minute delay.

The only difference between my script and yours is that i am reading the whole file at once, whereas you are reading a small buffer. I will try your solution in my script to see if it "fixes" it.