View Single Post
Old 06-04-2011, 06:31 AM  
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,386

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?
__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote