I have a php script that reads RSS feed and displays the items on the page:
<?php
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
$j=0;
foreach($x->channel->item as $entry) {
if ($i <5){
echo "<li>
<a href='$entry->link' title='$entry->title'>" .
$entry->title . "</a><br/>
<span style='color: 444444;'>".$entry->description."
</span>..<a href='$entry->link' title='$entry->title'>
<b>more</b></a>
</li>";
}$i +=1;
}
}
getFeed("http://example.org/feed/");
?>
It works well and displays the RSS item with the links in it. The issue is when the rss feed is down or becomes 0byte size file and it does not show anything. Is there a way to check if the file exists and not empty and make this script fail gracefully way before the server times out?