如何为PHP文件启用mod_deflate?

DM.*_*DM. 2 php .htaccess gzip mod-deflate httpd.conf

我有一个Liquid Web VPS帐户,我已确保mod_deflate已安装且正在运行/活动.

我曾经通过PHP gzip我的css和js文件,以及我的PHP文件本身...但是,我现在尝试通过mod_deflate这样做,它似乎适用于除PHP文件之外的所有文件.(Txt文件工作正常,css,js,静态HTML文件,只是通过PHP文件生成的任何内容.)我该如何解决这个问题?

(我使用了cPanel中"优化网站"下的"压缩所有内容"选项,它在主目录中创建了一个.htaccess文件(不是public_html,高出一个级别),文本与"压缩除图像之外的所有内容"完全相同" http://httpd.apache.org/docs/2.0/mod/mod_deflate.html上的示例)

.htaccess文件:

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip

        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>
Run Code Online (Sandbox Code Playgroud)

DM.*_*DM. 5

自从我发布这个问题已经有一段时间了 - 我最终通过PHP.ini启用zlib压缩,因此zlib压缩PHP输出,而mod_deflate压缩其他所有内容.

我在想它不工作的原因(mod_deflate不是压缩PHP输出)与运行CGI而不是Apache DSO的PHP有关...

  • 你能解释一下如何在php.ini文件中启用zlib压缩吗?代码是什么? (3认同)