开发者

How do you set the correct Content-Length header when the webserver automatically compresses output?

开发者 https://www.devze.com 2022-12-21 00:26 出处:网络
Following my previous question, in which I think I\'ve narrowed my problem down to the bottleneck开发者_StackOverflow社区:

Following my previous question, in which I think I've narrowed my problem down to the bottleneck开发者_StackOverflow社区:

How do I set the correct value for the Content-Length header for a downloadable file, from within PHP, when the webserver (apache) automatically compresses the ouput afterwards?

I'm looking for the most robust/generic solution. I'm not well informed about output compression, but I presume apache has several compression algorithms it can utilize (gzip, etc?). So, from within PHP, how would I automatically discover what compression the webserver uses, and how can I use this to set the correct Content-Length header value for the filesize of the file (after it's been compressed)?


You don’t need to specify Content-Length, Apache does that for you.


Okay, so the situation here is you issue a file download. I bet that file is already compressed to save you some bandwidth.

Anyway, if your server has any compression active, that's not good, as it spends time for nothing as the server can't achieve a better compression, so for speeding this up, you should disable output compress for any file download.

try from these:

apache conf
Disable mod_deflate

php.ini
output_buffering = Off
output_handler =
zlib.output_compression = Off


Maybe cletus's answer in this question helps.

Also, are you sure you want to serve your downloads using gzip? Zipping makes much sense for HTML, CSS and JS contents, but with huge file downloads, I would turn it off.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号