I want to cache the images of my gallery. Generating images every pages load using GD uses a lot of memory, So I am planning to create a cache image for the images generated by php script done with GD. What will be the best thing to create cache?
Yes I read it a while ago before posting my question.. But I don't have any idea on how caching is made with PHP, yes i was able to generate an image but how generated images can transform into cache image.
christian
2010-03-16 08:19:15
I usually found cache into hash forms. Is webserver also take care of hashing? Can you explain or give an example how webserver take care of caching.
christian
2010-03-16 09:12:25
By it's purpose. It were designed to cache, as it HTTP server and HTTP protocol support caching. It manages to calculate a hash.
Col. Shrapnel
2010-03-16 11:34:20
+2
A:
Use something like
$mime_type = "image/png";
$extension = ".png";
$cache_folder = "cache";
$hash = md5($unique . $things . $for . $each . $image);
$cache_filename = $cache_folder . '/' . $hash . $extension;
//Is already it cached?
if($file = @fopen($cache_filename,'rb')) {
header('Content-type: ' . $mime_type);
while(!feof($file)) { print(($buffer = fread($file,4096))); }
fclose($file);
exit;
} else {
//Generage a new image and save it
imagepng($image,$cache_filename); //Saves it to the given folder
//Send image
header('Content-type: ' . $mime_type);
imagepng($image);
}
Pez Cuckow
2010-05-09 12:05:32