Use php readfile () or redirect to display image file?

I have a directory outside of webroot with images, css and javascripts.
These files change frequently.
I could write a script that finds the file, determines the type of mime and displays it in the browser.
Or
I can find the file, copy it to a web-accessible directory and redirect to that file using the header location. When the file is requested again, it will first check if the file has been modified, and then redirect again.

What would be better? Each request to the readfile or each request will timestamp and redirect (so 2 ​​requests instead of one)

+2
source share
3 answers

The first rule of performance: control, do not speculate.

I will immediately break this first rule and assume that the readfile will be faster because it eliminates the network circuit.

How many do you need? The fastest way to do this is to install a separate web server for static content under a subdomain (for example, http://static.mysite.com/foo.jpg ) on a completely different machine, and then let this web server handle frequently changing image / files css / javascript.

+2
source

: , , - ? exec() ln, , , PHP symlink().

+1

, ? "" , - , , , .

, , :)

+1

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


All Articles