|  | Posted by Al on 02/09/05 00:36 
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.
 
 Al....
 
 
 
 
 
 
 
 Al wrote:
 
 > How can I detect that a remote server is hung up on transmitting a http
 > page and gracefully handle it?
 >
 > The connect is made OK, all I want to do is to make certain that I
 > receive the data stream in a given amount of time.  For example, if the
 > remote server is incredibly slow or hangs in the middle of transmitting
 > the data.
 >
 > e.g.
 >
 >> $fp= fopen("http://www.anything.com/foo.html, 'rb');
 >> if(!fp) {do something different}
 >>
 >> stream_set_timeout($fp, 2);
 >>
 >> $status= stream_get_meta_data($fp);
 >>
 >> if($status[timed_out] {do something};
 >
 >
 > $status[timed_out] never shows anything but 0.  I've tried it with a 4mb
 > file and the timeout = 1sec.
 >
 > error reporting shows nothing. It's as if socket connections don't
 > trigger timeout errors, including the max_execution_time.
 >
 > I've spent some time poking around the php manual and Googling and can't
 > find anything appropriate.  One ref I found said there is no way to do
 > this.
 >
 > Anyone have a suggestion?
 >
 > Al.....
  Navigation: [Reply to this message] |