Skip to content

Instantly share code, notes, and snippets.

@gabrieledarrigo
Created November 20, 2012 09:04
Show Gist options
  • Save gabrieledarrigo/4116855 to your computer and use it in GitHub Desktop.
Save gabrieledarrigo/4116855 to your computer and use it in GitHub Desktop.
Simple Caching System for a single file
// Caching system; se il file è meno recente di un ora viene rieseguita la chiamata e il file locale viene sovrascritto.
if (file_exists($filename) && filemtime($filename) > (time() - 60 * 60)) {
$feed = simplexml_load_file('feed.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
} else {
$remoteFile = file_get_contents('http://remotefile.xml');
file_put_contents($filename, $remoteFile, LOCK_EX);
$feed = simplexml_load_file('feed.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment