Answer the question
In order to leave comments, you need to log in
How to implement image resizing on the fly using php?
Good afternoon!
There was a question about optimizing the image resizing process using php on the fly. The resize link looks like this:
localhost/$controller/$config/$token/$image- >id.$image->format
The controller checks the token (it is unique for each image) so that the link is not forged. And if it is valid, the path to the image from the database to the id is obtained, the content is resized according to the config and given to the browser with headers. The whole thing is cached by Nginx for a month, so that when you request it again, it immediately returns the image from the cache.
It is necessary to make such a moment, if suddenly the storage has fallen off and there are no pictures, then a stub picture is given. And naturally, it gets into the Nginx cache, and even when the pictures appear, the cache is still given away, and you have to clean it, and this creates a significant load.
Can you please tell me how to solve this situation?
Answer the question
In order to leave comments, you need to log in
This can be solved at the nginx level with try_files and X-Accel-Redirect, no cache at all.
For example, like this:
location <локейшен с картинками>{
try_files $uri @resize;
}
location @resize {
proxy_pass http://<адрес ресайзера с параметрами>;
}
location /notexist.gif {
root /path/to/notexist/folder;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question