在Solaris上有一个Apache服务器正在发送“Transfer-Encoding:chunked”,而不是发送我在PHP(用于下载文件)中的“Content-Length”头。 你知道一个方法来防止这个吗?
谢谢
请参阅: https : //stackoverflow.com/questions/1334471/content-length-header-always-zero
我已经试过了这个指令
SetEnvIfNoCase Request_URI get_file\.php$ no-gzip dont-vary
现在我得到一个与原始文件大小相同的文件,但文件已损坏。 以下是从服务器收到的标题:
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
如果Apache在发送之前不知道总输出大小,则发生分块输出,就像压缩传输一样(Apache在达到一定大小时将数据压缩成块,然后在脚本仍在执行时将其分派给浏览器/请求者)。 你可能会看到这个,因为你有mod_deflate或mod_gzip活动。 你可以在这里validation这是否是你的问题。
你可以像这样禁用每个文件的mod_deflate ( 更多这里 )
SetEnvIfNoCase Request_URI get_file \ .php $ no-gzip dont-vary
一般来说,这是最好的,因为它大大提高了数据传输的速度。
如果Apache 2输出filter看到stream结束标记(EOS)并且没有发送任何内容,则会自动添加内容长度标头。 源代码:
if (ctx->data_sent == 0 && eos) { ap_set_content_length(r, r->bytes_sent); }
如果PHP在发送EOS之前将任何数据传递给Apache,则会发生分块。 PHP默认使用4096字节的输出缓冲区。 任何小于这个的页面都不会被分块。
同时检查内容是否通过gzip(mod_gzip)进行传递,并获得压缩后,apache将转向分块编码。