|
Posted by Ben Jamieson on 10/21/05 21:26
Hi all, I need some help, as this one is driving me mad.... if anyone
could assist, I would be hugely appreciative!
OK, Here's my code:
<?php
$query_timeout= 4 ;
$url="http://my.test.com";
$fp = fopen ($url, 'rb');
$chunk = fread($fp, 2000);
stream_set_timeout($fp, $query_timeout);
$status = stream_get_meta_data($fp);
fclose($fp);
if ($status['timed_out']) {
echo 'Connection timed out!';
} else {
echo "Contents: ". $chunk;
}
?>
The URL I am accessing is often unavailable, as the server goes down a
lot. Shouldn't this script simply give up after 4 seconds? It doesn't.
It times out after ~2 minutes.
Every time, after 2 minutes, I see on screen:
Contents:
(nothing else, as the URL couldn't be opened cos the server is down.)
Surely I should be seeing:
Connection Timed Out
Any clues as to what I am doing wrong here?
TIA
Ben
Navigation:
[Reply to this message]
|