Marcel.de.Haas Posted September 3, 2008 Share Posted September 3, 2008 Hi All, I have searched this forum for a solution, but I cannot find exactly what I need and my PHP is too rusty to complete this task by myself. I have the following script which gets an image, resizes it and outputs the resampled image. It ran like a charm, but the source web server is experiencing heavy loads and regularly returns en error 500. So I want the script to cache the image on the server where the script runs (Which is fully under my control). The image on the source server is update once every week (or less frequently if I don't provide new input). So what I would like is the following: * Use cached data when the cache is less than 24 hours old * Update cached image if the cached image is older than 24 hours * Allow argument to the script to force update the image (?update=force) * When the server returns an Error 500 or server or image isn't found use the cached data even when update is forced. Here is the script I have in place now: <?php // File and new size $filename = 'http://www.itsnotaboutthenumbers.com/europe_findsmap_export.php?id=1094028'; $percent = 0.35; // Content type header('Content-type: image/png'); // Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); // Resize without visible artifacts imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagepng($thumb); ?> Link to comment https://forums.phpfreaks.com/topic/122510-need-local-caching-for-this-image-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.