Created
November 20, 2012 09:04
-
-
Save gabrieledarrigo/4116855 to your computer and use it in GitHub Desktop.
Simple Caching System for a single file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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