Here is the same code but with hourly cashing:
Code:
<?php
$feed = file_get_contents ( "http://nubilestube.com/rss.php?location=most_recent" );
$filename = "cache.txt";
if (file_exists ( $filename ) && (time () - filectime ( $filename )) < 60 * 60) {
$content = file_get_contents ( $filename );
} else {
$xml_parser = xml_parser_create ();
xml_parse_into_struct ( $xml_parser, $feed, $vals, $index );
$cnt = count ( $index ["TITLE"] );
$content = "";
for($i = 1; $i < $cnt; $i ++) {
$content .= "<h3>" . html_entity_decode ( $vals [$index ["TITLE"] [$i]] ["value"], ENT_QUOTES ) . "</h3>\n";
$content .= "<p>" . html_entity_decode ( $vals [$index ["DESCRIPTION"] [$i]] ["value"], ENT_QUOTES ) . "</p>\n";
}
file_put_contents($filename, $content, LOCK_EX);
xml_parser_free ( $xml_parser );
}
echo $content;
?>
You just need to create the empty file "cache.txt" and chmod it to 666.
Can't be easier, right?
