I am using Laravel Storage and I want to serve users some (larger than memory limit) files. My code was inspired from a post in SO and it goes like this:
$fs
X-Send-File
.
X-Send-File
is an internal directive that has variants for Apache, nginx, and lighthttpd. It allows you to completely skip distributing a file through PHP and is an instruction that tells the webserver what to send as a response instead of the actual response from the FastCGI.
I've dealt with this before on a personal project and if you want to see the sum of my work, you can access it here:
https://github.com/infinity-next/infinity-next/blob/master/app/Http/Controllers/Content/ImageController.php#L250-L450
This deals not only with distributing files, but handling streaming media seeking. You are free to use that code.
Here is the official nginx documentation on X-Send-File
.
https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/
You do have to edit your webserver and mark specific directories as internal for nginx to comply with X-Send-File
directives.
I have example configuration for both Apache and nginx for my above code here.
https://github.com/infinity-next/infinity-next/wiki/Installation
This has been tested on high-traffic websites. Do not buffer media through a PHP Daemon unless your site has next to no traffic or you're bleeding resources.