simpleXML - simplexml_load_file() timeout?
| From: | darren kirby | Date: | Mon, 10 Apr 2006 19:25:47 +0000 |
| Subject: | simpleXML - simplexml_load_file() timeout? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-233687@lists.php.net to get a copy of this message | ||
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("&", "&", $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: [application/pgp-signature]
Attachment: [application/pgp-signature]