Skip to content

Instantly share code, notes, and snippets.

@muthu32
Created February 23, 2018 05:55
Show Gist options
  • Save muthu32/3062b7266aacd91e72e5ed541b58a646 to your computer and use it in GitHub Desktop.
Save muthu32/3062b7266aacd91e72e5ed541b58a646 to your computer and use it in GitHub Desktop.
Cache headers for images
header('Content-Type: image/png');
$modified = $ch->lastmodified();
if($modified)
{
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $modified)
{
header('HTTP/1.0 304 Not Modified'); exit();
}
//echo $modified;
header('Last-Modified: ' .gmdate('D, d M Y H:i:s T', $modified).' GMT');
}
header("Cache-Control: max-age=2592000"); //60*60*6 = 6 hours
header("User-Cache-Control: max-age=2592000");
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60*6))); //6 hours
header("Pragma: cache");
imagepng($im);
imagedestroy($im);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment