On Mon, 2006-04-10 at 15:25, 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";
> }

Why do you do this on every request? Why not have a cron job retrieve an
update every 20 minutes or whatnot and stuff it into a database table
for your page to access? Then if the cron fails to retrieve the feed it
can just leave the table as is, and your visitors can happily view
slightly outdated feeds? Additionally this will be so much faster that
your users might even hang around on your site :)

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

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

Reply via email to