Re: simpleXML - simplexml_load_file() timeout?

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

 



On Mon, April 10, 2006 6:17 pm, Rasmus Lerdorf wrote:
> Martin Alterisio wrote:
>> Maybe you can read the contents of the feeds using fsockopen() and
>> stream_set_timeout() to adjust the timeout, or stream_set_blocking()
>> to read it asynchronously, and then load the xml with
>> simplexml_load_string().
>>
>> PS: I forgot to reply to all and mention you'll have to send the GET
>> http command and headers, check the php manual for examples.
>
> You can just use fopen() to avoid all that.

No, he can't.

Sorry, Rasmus. :-)

If the URL is not working at the time of fopen() then you'll sit there
spinning your wheels waiting for fopen() itself to timeout, before you
ever GET a valid file handle to which one can apply stream_set_timeout
and/or stream_set_blocking.

That can take MUCH too long.

So you're STUCK with fsockopen, which DOES take a timeout parameter
for OPENING the socket, as well as giving one a stream to which
stream_set_blocking and stream_set_timeout can be applied.

But then you are stuck re-inventing the damn wheel with any protocol
you'd like to support like GET/POST, HTTPS (ugh!), FTP and so on.

All of which is buried in the guts of the Truly Nifty fopen,
file_get_contents, and so forth, but is utterly useless if you care at
all about timing out in a reasonably-responsive application.

So you have do all the junk to send things like:
GET / HTTP/1.0
Host: example.com
yourself, and God help you if you want to support HTTPS.

Actually, curl MAY be the better solution -- but my boss doesn't have
curl installed, so I was screwed anyway...

This is why I (and others) have put in a Feature Request to get
fopen() and friends to have some kind of programmatically changable
timeout setting.  Said Feature Requests invariably get marked "Bogus"
and then commented with something like the non-solution above. :-)

Oh well.

It *can* be done; You just have to type WAY too much junk to do
something very simple and very commonly needed.

-- 
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