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

StackOverflow https://stackoverflow.com/questions/2287950

문제

Following my previous question, in which I think I've narrowed my problem down to the bottleneck:

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top