When spitting out images with php the browser doesn't seem to cache the resulting image.
because the browsers were no caching the images.
Tthe image script here pulled off 400mb in 3 days:http://ruralromeos.com/new_singles.php
Here's the fix:
session_start(); // if you are using sessions.
// not sure if this stuff is really needed, but works:
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,strtotime("+2 day")));
// the browser will send a $_SERVER['HTTP_IF_MODIFIED_SINCE']
// option 1, you can just check if the browser is sendin this
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
// if the browser has a cached version of this image, send 304
header('Last-Modified: '.$_SERVER['HTTP_IF_MODIFIED_SINCE'],true,304);
exit;
}
// option 2, if you have a file to base your mod date off:
$img = "some_image.png";
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
&&
(strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($img))) {
// send the last mod time of the file back
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($img)).' GMT',
true, 304);
exit;
}
// and here we send the image to the browse with all the stuff
// required for tell it to cache
header("Content-type: image/jpeg");
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($img)) . ' GMT');
// use ob buffering to find the image size.
ob_start();
imagejpeg($image,null,100);
$ImageData = ob_get_contents();
$ImageDataLength = ob_get_length();
ob_end_clean();
header("Content-Length: ".$ImageDataLength);
echo $ImageData;
imagedestroy($image);
|
Collector Comics is THE place to buy, sell, and research comics online. Launching soon.
Launch »
Screenshot »
|
|
Webitor is a kick-ass easy to use, easy to extend, non-database driven Content Management System. Version 2 with reseller plan coming soon.
Launch »
Version 1 »
|
|
GC Lounge is my own pet social network and test bed for social related code. Made by locals for locals.
Launch »
|
|
GG has indexed over half a million recent Trade Mark applications. This revolutionary tool is extremely valuable for industry experts.
Launch »
|
|
GCWiFi is the hub for techies interested in joining a ad-hoc wireless mesh spread across the Gold Coast
Launch »
|
|
Web based financial client management system
Launch »
|
|
OS Commerce modules and template modification
Launch »
|
| View More Projects » | |