|
Posted by Janwillem Borleffs on 10/21/05 22:53
Ben Jamieson wrote:
> 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.
>
There are a couple of things going wrong here. First, you call
stream_set_timeout() after you have called fread(), while it should be the
other way around.
Second, the stream_set_timeout() function only works on the output stream of
the connection, *after* the connection to the remote source has been
established. When the stream doesn't timeout, but the connection does,
stream_get_meta_data() won't get anything.
What you need to catch this, is a way to set the timeout for the connection.
Since PHP5, you can do this with the fopen() function by using the 4th
argument to this function (see the manual for more info). Using a lower
version, you can apply the fsockopen() function, which accepts a timeout as
one of its arguments; see: http://www.php.net/fsockopen.
JW
[Back to original message]
|