Skip to content

Instantly share code, notes, and snippets.

@JaheMerah
Last active April 6, 2017 17:29
Show Gist options
  • Save JaheMerah/56cde9d6c7f2b644c729dc019b187904 to your computer and use it in GitHub Desktop.
Save JaheMerah/56cde9d6c7f2b644c729dc019b187904 to your computer and use it in GitHub Desktop.
file_get_contents file_put_contents
<?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