Apache / 2.2.20(Ubuntu 11.10)gzip压缩不能在php页面上工作,内容被分块

我遇到了一个新的生产服务器,我转移项目的问题。 PHP应用程序的HTML输出没有被Apache mod_deflate模块压缩。 其他资源,比如样式表和JavaScript文件,甚至包含与PHP输出相同Content-type(text / html)的html页面,都被压缩了!

这些项目在.htaccess中使用以下规则(来自HTML5样板):

 <IfModule mod_deflate.c>
   #Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
   <IfModule mod_setenvif.c>
     <IfModule mod_headers.c>
       SetEnvIfNoCase ^(Accept-EncodXng | X-cept-Encoding | X {15} |〜{15} |  -  {15})$ ^((gzip | deflate)\ s *,?\ s *)+ | [X〜 - ] {4,13} $ HAVE_Accept-Encoding
       RequestHeader追加Accept-Encoding“gzip,deflate”env = HAVE_Accept-Encoding
     </ IfModule>configuration
   </ IfModule>configuration

   #HTML,TXT,CSS,JavaScript,JSON,XML,HTC:
   <IfModule filter_module>
     FilterDeclare COMPRESS
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ text / html
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ text / css
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ text / plain
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ text / xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ text / x-component
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / javascript
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / json
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / xhtml + xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / rss + xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / atom + xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / vnd.ms-fontobject
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ image / svg + xml
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ image / x-icon
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ application / x-font-ttf
     FilterProvider COMPRESS DEFLATE resp = Content-Type $ font / opentype
     FilterChain COMPRESS
     FilterProtocol COMPRESS DEFLATE change = yes; byteranges = no
   </ IfModule>configuration
  </ IfModule>configuration                                                                                                                                                                 

我们有一台运行相同的Apache,OS和PHP版本的testing机器。 在那台机器上,压缩在PHP输出上工作得很好。 我已经检查并比较了Apache和PHPconfiguration文件,就我所知,完全相同。

我已经尝试了几种输出PHP内容的方式,使用输出缓冲或简单地回显内容。 同样的事情,没有压缩。

PHP输出的示例响应标题:

 HTTP / 1.1 200 OK
date:2012年4月25日星期三23:30:59 GMT
服务器:Apache
接受范围:字节
有效期至:1981年11月19日星期四08:52:00 GMT
caching控制:公共
 Pragma:no-cache
 Vary:用户代理
保持活跃:超时= 5,最大= 98
连接:保持活跃
传输编码:分块
 Content-Type:text / html; 字符集= utf-8的

一个css文件的响应头示例:

 HTTP / 1.1 200 OK
date:2012年4月25日星期三23:30:59 GMT
服务器:Apache
 Last-Modified:Mon,04 Jul 2011 19:12:36 GMT
 Vary:Accept-Encoding,User-Agent
内容编码:gzip
caching控制:公共
到期时间:2012年5月25日星期五23:30:59 GMT
内容长度:714
保持活跃:超时= 5,最大= 100
连接:保持活跃
 Content-Type:text / css; 字符集= utf-8的

有没有人有线索或遇到同样的“问题”?

谢谢!

如果Apache无法确定返回的内容有多大,它将自动使用分块编码 。 根据您的PHP脚本运行的方式(CGI,FastCGI等),Apache可能在开始将其返回给用户时不知道内容的大小。 即,如果您在整个脚本中输出内容,则可能会立即将该数据写入客户端缓冲区。

它与静态文件一起工作的原因是Apache在开始返回时知道它们的大小。 这可能会指出你的Apache / PHPconfiguration有问题(例如,它开始写输出从脚本返回的时刻),或脚本本身的工作方式。

换句话说,这听起来像是PHP或Apache / PHP连接器的问题,而不是mod_deflate

请检查是否启用PHP输出的压缩。 这可以在php.ini文件中或通过运行时指令来完成。 检查文档的更多细节。