This file contains hidden or 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
| https://davidwalsh.name/php-cache-function | |
| /* gets the contents of a file if it exists, otherwise grabs and caches */ | |
| function get_content($file,$url,$hours = 24,$fn = '',$fn_args = '') { | |
| //vars | |
| $current_time = time(); $expire_time = $hours * 60 * 60; $file_time = filemtime($file); | |
| //decisions, decisions | |
| if(file_exists($file) && ($current_time - $expire_time < $file_time)) { | |
| //echo 'returning from cached file'; | |
| return file_get_contents($file); |