Last active
April 6, 2017 17:29
-
-
Save JaheMerah/56cde9d6c7f2b644c729dc019b187904 to your computer and use it in GitHub Desktop.
file_get_contents file_put_contents
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
<?php | |
function file_get_cached($url) | |
{ | |
//config | |
$dir = 'cache'; | |
$day = 86400; //seconds | |
$file = $dir . DIRECTORY_SEPARATOR . md5($url); | |
if (file_exists($file) && filemtime($file) > (time() - $day)) { | |
$o = file_get_contents($file); | |
} | |
else | |
{ | |
$o = file_get_contents($url); | |
file_put_contents($file, $o); | |
} | |
return $o; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment