Re: simpleXML - simplexml_load_file() timeout?

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

 



Maybe it's too late to say this, but if your real problem is that you don't want the function reading the rss feed to block the rest of your page, you can always put the output of the reading of the feed
on a separate page, and include this through an iframe.

darren kirby wrote:

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

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