Closed alexander-schranz closed 2 years ago
Hey @alexander-schranz. Thanks for the proposal. Could you please provide a little bit more details about how this feature works in Nginx, Apache, or Symfony? Might be some documentation. Thanks 👍🏻
@rustatian The response from PHP looks like the following in HTTP:
HTTP/1.1 200 OK
x-sendfile: /var/data/website/private-directory/file.mp4
Content-Length: 12345
The content
of this response is empty and does not contain any data the Content-Length
can still return the original length of the given file.
The webservers looks for the x-sendfile
header if it exist it will stream the given file as response content to the user and remove the x-sendfile
header from the response. The advantage is php does not need to stream it to the webserver and then webserver to the client just the webserver does stream the file directly from the
There is also some docs here:
https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/
https://httpd.apache.org/docs/2.4/en/mod/core.html (see also https://tn123.org/mod_xsendfile/)
In symfony the x-sendfile
header is only written when the x-sendfile-type
seems to be given to the requests and no accel map is given:
Great, thanks @alexander-schranz. I hope I'll implement it after the transition of the jobs
and grpc
will be done.
Valery, this work is pretty much connected with the custom response handlers we spoke about (streaming), since we will use a similar approach with the header. So it will require some HTTP layer refactoring first. But it will open a TON of interesting possibilities:
Also, it is connected to one of the distribution methods of https://github.com/spiral/distribution
Feature accepted for the v2.5.0
@alexander-schranz Feature will be available for testing by the end of the week in the v2.5.0-beta.2
.
Awesome thank you all 👍
@alexander-schranz Please, test the v2.5.0-beta.2
: https://github.com/spiral/roadrunner-binary/releases/tag/v2.5.0-beta.2
Is your feature request related to a problem? Please describe.
When having private files behind a PHP firewall you return them in Symfony as a BinaryFileResponse. When supported by the Webserver in this case the
x-sendfile
header will be used which just tell the webserver where the file can be found which need to be streamed out.Describe the solution you'd like
It would be great when roadrunner would also support the x-sendfile header. I could not yet find a reference or a config how this kind of response are handled in roadrunner.
Describe alternatives you've considered
Alternative is not supporting
x-sendfile
Symfony does then fallback to a normal file stream to php://output.Additional context
Apache does support x-sendfile of the sendfile mod. Nginx I think does support it out of the box. The state of caddy webserver I don't know.