There is an Apache server on Solaris that is sending 'Transfer-Encoding: chunked' and not sending the 'Content-Length' header that I have in my PHP (used for downloading files). Do you know a way to prevent this?
Thanks
See: https://stackoverflow.com/questions/1334471/content-length-header-always-zero
I have tried the directive
SetEnvIfNoCase Request_URI get_file\.php$ no-gzip dont-vary
and now I get a file with the same file size of the original, but the file is corrupted. Here are the headers received from the server:
http://example.com/output_file_download.php?fileID=130
GET /output_file_download.php?fileID=130 HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: user_id=7C%25R; intrauser=kE06Ub%238+2dHT%29U0t%28B%2A; intrakey=rtacconi; PHPSESSID=5a3f8edff822474f3b95b6a6e5c87ad2
HTTP/1.x 200 OK
Date: Thu, 03 Sep 2009 10:02:05 GMT
Server: Apache
Expires: 0
Cache-Control: private
Pragma: public
Content-Description: File Transfer
Content-Disposition: attachment; filename=alfresco-logo.gif
Content-Transfer-Encoding: binary
Content-Length: 2401
Keep-Alive: timeout=15, max=500
Connection: Keep-Alive
Content-Type: application/octet-stream
Chunked output occurs when Apache doesn't know the total output size before sending, as is the case with compressed transfer (Apache compresses data into chunks when they reach a certain size, then despatches them to the browser/requester while the script is still executing). You could be seeing this because you have
mod_deflate
ormod_gzip
active. You can verify if this is your issue here.You can disable
mod_deflate
per file like so (more here)It's best left on in general as it greatly increases the speed of data transfer.
The Apache 2 output filter will automatically add a content-length header if it sees an end-of-stream marker (EOS) AND nothing has been sent yet. source code:
If PHP passes any data down to Apache before it sends EOS, then chunking happens. PHP uses a output buffer of 4096 bytes by default. Any page smaller than that will not get chunked.
Also check if the content is fed via gzip (mod_gzip) and gets compressed apache will then turn to chunked encoding.