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

后端 未结 3 995
孤独总比滥情好
孤独总比滥情好 2021-01-21 16:59

I\'ve a directory outside the webroot with images, css and javascripts.
These files often change.
I could write a script which locates the file, figures out the mime

相关标签:
3条回答
  • 2021-01-21 17:39

    How about a symbolic link directly to the file, not the entire directory? You could even make it a 'static' filename, and then let the web server do the modification timestamp check and caching, which would likely be much, much faster.

    Benchmarks though, of course :)

    0 讨论(0)
  • 2021-01-21 17:53

    First rule of performance: benchmark, don't speculate.

    I'll promptly break that first rule and speculate that the readfile will be faster, because it eliminates a network round-trip.

    How much performance do you need? The very fastest way to do this would be to setup a separate static-content web server under a subdomain (e.g. http://static.mysite.com/foo.jpg ) on a completely different machine, and then let that web server there handle the often-changing image/css/javascript files.

    0 讨论(0)
  • 2021-01-21 17:58

    Another suggestion: if you have control of the filesystem, you could perhaps create a symbolic link in the web-accessable directory to the image file? Either using exec() to invoke the 'ln' command or maybe the PHP symlink() function might work.

    0 讨论(0)
提交回复
热议问题