Re: URL -> stream context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, January 19, 2006 6:49 pm, Geoff wrote:
> Richard, have you seen this:
> http://bugs.php.net/bug.php?id=5153&edit=1
> 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 = 'https://example.com';
$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
got:
  $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?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux