I've got a redirect setup that searches for a picture inside a directory and when it doesn't exist, it'll redirect to some php file that resizes a picture and saves it to that particular directory. I first got it to operate great. Problem now's that I have to find a great way to redirect it when the image which was written is 4 hrs old. I investigated Mod_expires but tend to not try to redirect to my php image resizer once the image is 4 hrs old.

I understand I possibly could do that in PHP however the whole idea ended up being to lessen the server load by utilizing apache rather than PHP. The website I am focusing on will get several 1000 audiences daily and so i really should effectively cache the resized images. Here's a good example of what I am doing...

  1. Browser demands "http://images.mydomain.com/image/1234_01_thumb.digital"
  2. Apache Inspections if "http://images.mydomain.com/image/1234_01_thumb.digital" is available
  3. If it doesn't exist, redirect to to "/image/re-size_image.php" and produce a thumbnail in "/images/" folder

Since I acquired that working how do you have it to redirect to "/image/re-size_image.php" once the "1234_01_thumb.digital" will get x hrs old? Sooner or later someone will have to update that photo particularly if they submitted the incorrect one therefore it can not be permanent.

Help. Thanks ahead of time!


You will get the file date after which make sure that from the current time()

say something similar to this:

$img_head = exif_read_data($img_path, 'IFD0');
if ($img_head != false) {
  if ($img_head['FILE.FileDateTime'] < (time() - 14400)) {
    header ("Location: old_image.php");

I am hoping you receive what I am saying because I am typing from the phone...

Well, I really hope someone corrects me if I am wrong, however the last I understood PHP operates like a module in Apache, via mod_php, so some way the net server continues to be needing to churn using your code.

Hmm. My original thought ended up being to set the cache-control value using something similar to:

<FilesMatch "\.(jpg|jpeg|png|gif)$">
Header set Cache-Control "max-age=14400, must-revalidate"

but that will not work. That will just tell Apache to seize a brand new copy from the image...


Yeah, @chris_mcclellan's idea is how I had been headed during my way of thinking. I'd run with this and find out whether it meets your speed and agility goals.