Created
January 4, 2017 16:50
-
-
Save daif/e18d9f0c92047e1415df57e8680e18c5 to your computer and use it in GitHub Desktop.
Revisions
-
daif created this gist
Jan 4, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <?php //Tiny Cache system function file_cache_contents($url, $cache_time=360000) { // 60*60*5 $cache_dir = __DIR__.'/cache/'; $cache_file = $cache_dir.md5($url).'.cache'; @mkdir($cache_dir, 0775, true); // return data from cached file if file exists and not expired if(file_exists($cache_file) && filemtime($cache_file)+$cache_time >= time()) { return(unserialize(file_get_contents($cache_file))); } // get data from url and cache it then return the data $cache_data = file_get_contents($url); file_put_contents($cache_file, serialize($cache_data), LOCK_EX); return($cache_data); } ?>