How to detect X-Accel-Redirect (Nginx) / X-Sendfile (Apache) support in PHP?

后端 未结 3 1939
粉色の甜心
粉色の甜心 2020-12-29 10:22

About Application

I am working on an e-commerce application in PHP. To keep URL\'s secure, product download links are kept behind PHP. There is a file, say downloa

3条回答
  •  难免孤独
    2020-12-29 10:48

    readfile does not take up a large amount of memory. It opens the file, reads a small portion, writes that portion to the browser and then reuses the memory for the next read. It's the same as using fread+echo in a while loop. You will not be constrained by memory-limits, but you will be limited by max_execution_time and such.

    If you want to use X-Accel-Redirect support (or similar) provided by your web server, send a header like this (for Nginx):

    header('X-Accel-Redirect: /path/to/file');
    

    Your application cannot know if the server supports this. You will need to provide a configuration option so the admin/installer of your software can provide such information manually.

提交回复
热议问题