dtnpf35197 2016-07-01 08:46
浏览 40
已采纳

为什么gzip压缩不适用于PHP处理的文件?

I have two files named test.html and test.php on my server, having the same content:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>TEMPLATE</title>
</head>
<body>

  TEXT

</body>
</html>

Besides that I have a .htaccess-files with the following content:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.(php3|php4|php5|php6|html|htm) $1\.php

AddType x-mapp-php5.5 .php
AddHandler x-mapp-php5.5 .php

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
</Ifmodule>

Requesting test.html returns the following headers:

Connection: Keep-Alive
Content-Type: text/html
Date: Fri, 01 Jul 2016 08:32:04 GMT
Keep-Alive: timeout=2, max=200
Server: Apache
Transfer-Encoding: chunked
x-powered-by: PHP/5.5.36

After uncommenting the rewrite part (thus using HTML without beeing processed by PHP), the response headers are:

Accept-Ranges: bytes
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 186
Content-Type: text/html
Date: Fri, 01 Jul 2016 08:42:22 GMT
Etag: "xxxxxxxx-xx-xxxxxxxxxxxxx"
Keep-Alive: timeout=2, max=200
Last-Modified: Fri, 01 Jul 2016 08:42:03 GMT
Server: Apache
Vary: Accept-Encoding

It's exactly the same content and exactly the same header, but why is the content not compressed, when it is returned by PHP?

  • 写回答

1条回答 默认 最新

  • duan41497 2016-07-01 09:11
    关注

    Add the following line in your .htaccess

    php_value zlib.output_compression 1
    

    to enable PHP output compression.

    More information at http://php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog