How to cache php generated image

I made a file to print the image file using W and H I define with the get method

but my problem is caching these images

i add these headers to the file

@header("Cache-Control: private, max-age=10800, pre-check=10800"); @header("Pragma: private"); @header("Expires: " . date(DATE_RFC822,filemtime($full_path))); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($full_path))) { // send the last mod time of the file back header('Last-Modified: '.gmdate('D, d MYH:i:s', filemtime($full_path)).' GMT',true, 304); exit; }else { @header('Last-Modified: ' . gmdate('D, d MYH:i:s', filemtime($full_path)) . ' GMT'); @header('Content-Type: image/jpeg'); @imagejpeg($image); } 

but my problem is that some pictures are cached in order, but others are not, and sometimes pictures inside the album are not displayed until I turn off the cache header

Are my headers correct ?, and about the cache should I use - or + to set the time cache, how does it work?

+6
source share
1 answer

because they use htaccess with mod_expires?

Example # 1:

 # enable expirations ExpiresActive On # expire GIF images after a month in the client cache ExpiresByType image/gif A2592000 # HTML documents are good for a week from the # time they were changed ExpiresByType text/html M604800 

Read this documentation

Example # 2:

 ExpiresActive On ExpiresDefault A0 ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/jpeg A2592000 
+1
source

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


All Articles