PHP Skip Slow

For various reasons, I need to play an intermediary between the HTTP request and the file on disk. My approach was to fill out the headers and then execute the readfile ('/path/to/file.jpg');

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

Can someone provide me with a more efficient way to stream the file to the client after sending the headers?

Note. This is a linux field in a shared hosting environment, if that matters

+3
source share
4 answers

Several web servers allow an external script to tell them to do just that. Apache's X- Sendfile (with mod_xsendfile) is one.

, , , - . X-Sendfile - .

+3

GET.

"Last-Modified" "304 Not Modified", "If-Modified-Since", , . ( "Cache-Control" / "Expires" ) .

, , , , .

0

It should be pretty fast. We did this with large images without any problems. Are you doing anything else before displaying the image, which can slow down the process, for example, computing some metadata on the image?

Edit: You may need to clear the output and use fread. IE:

$fp = fopen($strFile, "rb");
//start buffered download
while(!feof($fp))
    {
    print(fread($fp,1024*16));
    flush();
    ob_flush();
    }
fclose($fp);
0
source

Basically you want to build a server ... This is not trivial.

There is a very promising server project based on PHP: Nanoweb .

It is free and fully extensible.

-2
source

Source: https://habr.com/ru/post/1710589/


All Articles