You are here: Re: [PHP] URL -> stream context « PHP « IT news, forums, messages
Re: [PHP] URL -> stream context

Posted by "Richard Lynch" on 01/21/06 00:29

On Thu, January 19, 2006 6:49 pm, Geoff wrote:
> Richard, have you seen this:
> This bug goes back to June 2000. And it's closed even though it is
> clearly not fixed. Doesn't seem like they'll get to it anytime soon.
> You might have to do it the long way, building your own protocol
> handlers. Or, you might want to look into a 3rd party library, or a
> command line option like "lynx -dump -connect_timeout=n <uri>" which
> is multi-resource aware.

The comment in that bug report, and similar comments all over the 'net
by PHP Dev Team, are what led me on this quest in the first place...

Alas, the reality falls far short of what I had hoped was promised.

I *CAN* control the timeout, if I'm wiling to re-invent the wheel and
duplicate a ton of code that's built into fopen.

I *THOUGHT* from the comments that the new streams would have
something like fopen, with a configurable timeout, but with the
streams library handling all the minutia of different protocols.

As far as I can find, that's not the case.

Here is a crude version of what I would like to be able to type:
$url = '';
$stream_context = array('connection_timeout'=>4', 'url'=$url);
$stream = new stream($stream_context);
if ($stream === false) die("Connection timed out.");
stream_set_blocking($stream, false);
$start = time();
//Never ask the user to wait more than 5 seconds for a web page:
$data = '';
while ((time() <= $start + 5) && !feof($stream)){
$data .= fread($stream, 2048);
if (!feof($stream)){
//load obsolete data from cache, rather than incomplete data we just
$data = load_cache($url);

Instead, I have to know the ins and outs of all the different
protocols to even begin to use the new streams stuff.

Richard "unwillling" Lynch :-^

Like Music?



[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

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