Caching Generated Images Using PHP

I am trying to cache created images. Are you creating an image by accessing the file using resize.php? Width = x & height = y. If the image of this width and height does not exist, I use imagemagick to create it. However, if it exists, it is provided to the visitor.

Check! file_exists ($ name) works fine, so processing is not performed when it is not needed. However, it takes some time to download images.

Is my approach to the reading file incorrect or have the headers set incorrectly?

if (!file_exists($name)) {
 //image processing here
}
header("Content-Type: image/png");
header("Expires: Sat, 25 Jul 2020 10:00:00 GMT");
readfile($name);

Thank.

+3
source share
1 answer
+4

Source: https://habr.com/ru/post/1749953/


All Articles