Re: simpleXML - simplexml_load_file() timeout?

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

 



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.

2006/4/10, darren kirby <bulliver@xxxxxxxxxxxxxxx>:
> Hello all,
>
> My website uses simpleXML to print the headlines from a few different RSS
> feeds. The problem is that sometimes the remote feed is unavailable if there
> are problems with the remote site, and the result is that I must wait for 30
> seconds or so until the HTTP timeout occurs, delaying the rendering of my
> site.
>
> So far, I have moved the code that grabs the RSS feeds to the bottom of my
> page, so that the main page content is rendered first, but this is only a
> partial solution.
>
> Is there a way to give the simplexml_load_file() a 5 second timeout before
> giving up and moving on?
>
> Here is my function:
>
> function getFeed($remote) {
>     if (!$xml = simplexml_load_file($remote)) {
>         print "Feed unavailable";
>         return;
>     }
>     print "<ul>\n";
>     foreach ($xml->channel->item as $item) {
>         $cleaned = str_replace("&", "&amp;", $item->link);
>         print "<li><a href='$cleaned'>$item->title</a></li>\n";
>     }
>     print "</ul>\n";
> }
>
> PHP 5.1.2 on Linux.
> thanks,
> -d
> --
> darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
> "...the number of UNIX installations has grown to 10, with more expected..."
> - Dennis Ritchie and Ken Thompson, June 1972
>
>
>

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