You are here: Re: [PHP] stream_set_timeout() stream_get_meta_data() etc... « PHP « IT news, forums, messages
Re: [PHP] stream_set_timeout() stream_get_meta_data() etc...

Posted by Al on 02/09/05 00:46

Richard Lynch wrote:

> 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.
>
>
> That's exactly what stream_set_timeout does, *IF* more than 2 seconds goes
> by with *NO* data coming through.

How do I test the results of stream_set_timeout(). I've tried everything I can
think of and nothing shows, no error reports, nothing.


>
> If you want to put a cap on the total time spent, regardless of the file
> size, then do more like:
>
>
>>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);
>
> $start = time();
> while (!feof($fp)){
> $data = fread($fp, 10000); //10K chunks, change to suit
> if (time() - $start > 10){
> die("That's too slow!");
> }
> }
>

I tried something like this earlier, at your suggestion. Problem was that if
the server stalls in the middle of a chunk, it just hangs.



>
>>>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?
>
>
> Please review this exact same issue in the archives from the past week or
> two.

That was my thread. I didn't find a solution then and am back to it.

I seems as if stream_set_timeout() ought to be the right function; but, I can't
find a way to use it.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация