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

Posted by Jochem Maas on 01/19/06 13:17

Richard Lynch wrote:
> So I've been poring over the docs for the new stream stuff, and it
> looks pretty nifty, except...
>
> I'd really like to be able to just hand a URL to PHP like:
> http://php.net/manual/en/ref.stream.php

er you can if allow_url_fopen ini setting is set to 1 (can't you?)

$fh = fopen('http://php.net/');


for other kinds of streams (e.g. ftp?) you can write a userland
wrapper and register it so that you can use those kinds (e.g. ftp)
of urls with fopen et al:

http://www.php.net/manual/en/function.stream-wrapper-register.php

>
> And let PHP figure out how to create a stream context out of that, and
> which port to use, and how to do the GET to start things off, so I can
> just read my data.
>
> In other words, I'm greedy, and I want *BOTH* the simplicity of
> fopen() *and* the flexiblity of adding filters and all the fun new
> stuff.

well the manual (http://php.net/fopen) says:

$handle = fopen("/home/rasmus/file.txt", "r");
$handle = fopen("/home/rasmus/file.gif", "wb");
$handle = fopen("http://www.example.com/", "r");
$handle = fopen("ftp://user:password@example.com/somefile.txt", "w");

>
> I don't want to have to tear apart the URL myself and mess with
> sending 'GET ...' and 'host: ...'
>
> Did I miss a stream_url_to_context() function somewhere?...
>
> Not just parse_url() -- That will tear apart the URL, but then I have
> to do all the work that's buried in fopen()
>
> Bigger Picture:
> I have an old class that will take an array of HTTP URLs, and
> fsockopen them, set them non-blocking, and then fread() each in turn,
> and gather an array of results.
>
> The class has a 'timeout' parameter that limits how long it will wait
> for all this to happen.
>
> Each result set is marked as complete or incomplete.
>
> Complete results may be cached, for however long you choose in another
> setting.
>
> If results are incomplete, the cached version is used, no matter how
> obsolete. (This is for a search engine.)
>
> Blah, blah, blah.
>
> Anyway, I'd *LIKE* to be able to just allow *ANY* URL to be passed in,
> and have some nifty stream function, not unlike fopen(), that will
> take care of the grotty details of doing whatever it takes to get the
> data, but let me set the socket non-blocking and read them
> asynchronously.
>
> I feel like I must be missing something fundamentally simple here in
> all this stream stuff, but it's sure not obvious what I'm missing in
> the docs.

and maybe I'm completely misunderstanding you ;-/

>

 

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

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