We have a Laravel application and imagine the following: We have a slider with a play button that will start showing images on a slideshow. These images arrived from web cameras so obviously there are a lot of images. The load time of the page is horrible because it is trying to load ALL the images and often, even PHP runs out of memory trying to load all the images. Now, I can increase the amount of memory and execution time for PHP to keep doing it, but isn’t there a more sophisticated way to load these images depending on where do I scroll the slider or press the play button?
Also, one thing to keep in mind: Showing the images are behind an auth system so, not anyone is allowed to watch any camera. It depends on the rules and the users settings, etc…
Are these static images stored on a filesystem, and you are only using PHP to authorize access to them? In that case, don’t have PHP serve the image with
file_put_contents() or the like. Instead, after you have authorized the user, use nginx’s
X-Accel-Redirect to tell the nginx web server in front of PHP to serve the static file. (Lighttpd has a similar feature X-sendfile. Apache does not have such functionality built in, but a third party module exists.)
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.