Yii与ob_gzhandler;压缩html

时间:2012-07-19 16:17:33

标签: php html yii

我已将此代码添加到Yii上的配置文件main.php以压缩html标记

'preload'=>array('log'),
    'onBeginRequest' => create_function('$event', 'return ob_start("ob_gzhandler");'),  
    'onEndRequest' => create_function('$event', 'return ob_end_flush();'),

但是我和zlib有冲突怎么解决?

ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression'

3 个答案:

答案 0 :(得分:3)

您最好在yii级缩小 html代码

通过在.htaccess

中使用这样的段将gzip压缩到apache
<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/json application/javascript

# 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

# Do NOT compress localhost
#SetEnvIf Remote_Host 127.0.0.1 no-gzip

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

答案 1 :(得分:1)

这是PHP 5.4的错误:https://bugs.php.net/bug.php?id=62335

您可能需要使用以下内容禁用zlib

<?php ini_set('zlib.output_compression', 'Off'); ?>

答案 2 :(得分:0)

Apache的Google pagespeed模块与我一起工作,它预装在dreamhost和一些网络托管上:

https://developers.google.com/speed/pagespeed/module