Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP passthrough slow

Tags:

php

For various reasons, I need to play the intermediary between an HTTP Request and a file on disk. My approach has been to populate headers and then perform a readfile('/path/to/file.jpg');

Now, everything works fine, except that it returns even a medium sized image very slowly.

Can anyone provide me with a more efficient way of streaming the file to the client once the headers have been sent?

Note: it's a linux box in a shared hosting environment if it matters

like image 948
Allain Lalonde Avatar asked Sep 27 '26 00:09

Allain Lalonde


1 Answers

Several web servers allow an external script to tell them to do exactly this. X-Sendfile on Apache (with mod_xsendfile) is one.

In a nutshell, all you send is headers. The special X-Sendfile header instructs the web server to send the named file as the body of the response.

like image 186
Steve Madsen Avatar answered Sep 28 '26 17:09

Steve Madsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!