Skip to content

Instantly share code, notes, and snippets.

@guhemama
Last active December 10, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guhemama/4363114 to your computer and use it in GitHub Desktop.
Save guhemama/4363114 to your computer and use it in GitHub Desktop.
Simple PHP caching
<?php
$key = md5('url-goes-here');
$cache_file = getcwd() . "/{$key}";
if (file_exists($cache_file))
{
$html = file_get_contents($cache_file);
echo 'reading from cache';
}
else
{
$html = 'foo'; // remote request
file_put_contents($cache_file, $html);
echo 'reading from remote';
}
echo "\n{$html}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment