views:

204

answers:

3

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)?

A: 

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.

Pekka
*Content-Length* refers to the length of the HTTP message body. And if the message body is compressed, the *Content-Length* value reflects that.
Gumbo
Cheers @Gumbo, I wasn't sure myself.
Pekka
A: 

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

Pentium10
+2  A: 

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

Gumbo
That's what I assumed also, since Apache does the compressing, but I don't see it show up in FireFox's Live HTTP headers add-on. Are you sure this is the case?
fireeyedboy
@fireeyedboy: Hm, this must be an issue with your Apache. Because my local Apache sets the *Content-Length* field when using mod_deflate.
Gumbo