Best way to cache resized images using PHP and MySQL

Posted by Chris Hawes on Stack Overflow See other posts from Stack Overflow or by Chris Hawes
Published on 2008-09-26T17:13:31Z Indexed on 2010/04/04 0:23 UTC
Read the original article Hit count: 643

Filed under:
|
|
|

What would be the best practice way to handle the caching of images using PHP.

The filename is currently stored in a MySQL database which is renamed to a GUID on upload, along with the original filename and alt tag.

When the image is put into the HTML pages it is done so using a url such as '/images/get/200x200/{guid}.jpg which is rewritten to a php script. This allows my designers to specify (roughly - the source image maybe smaller) the file size.

The php script then creates a hash of the size (200x200 in the url) and the GUID filename and if the file has been generated before (file with the name of the hash exists in TMP directory) sends the file from the application TMP directory. If the hashed filename does not exist, then it is created, written to disk and served up in the same manner,

Is this efficient as it could be? (It also supports watermarking the images and the watermarking settings are stored in the hash as well, but thats out of scope for this.)

© Stack Overflow or respective owner

Related posts about php

Related posts about cache