simpleXML - simplexml_load_file() timeout?

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

 



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

Attachment: pgpq5wVj1WeMj.pgp
Description: PGP signature


[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