Quoting Al <[EMAIL PROTECTED]>:
> Darn, I left out an important function, the fread(). Code snip should be:
>   $fp= fopen("http://www.anything.com/foo.html, 'rb');
>   if(!fp) {do something different}
>   stream_set_timeout($fp, 2);
>   $contents= fread($fp, 200000);
>   $status= stream_get_meta_data($fp);
>   if($status[timed_out] {do something};
>
> It appears to me there is a basic logic problem.  The script must get
> past the fread() function before it gets to the stream_get_meta_data($fp).
> But, it hangs up on fread() and the script times out.

Set the stream to non-blocking mode (stream_set_blocking). Now all
read functions will return instantly, regardless if any data came
through. You can test whether you got back anything by checking the
returned data. If you now read from the non-blocked stream in a cycle,
you will have no "dead" times and you will always retain control.
Only now can you rely on comparing time() with a control value set
before entering the cycle and decide to abort if a number of seconds
has passed.

stream_set_timeout() will be pretty much superfluous at this point
and may even hinder your reading from the stream.

Important tip: in a non-blocking cycle you MUST have an usleep()
somewhere. Otherwise that cycle will consume 100% CPU while it
runs. An usleep(1000) will suffice, adjust as needed.

-- 
Romanian Web Developers - http://ROWD.ORG

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to