如何在zend Framework网站中设置gzip压缩 [英] How can I set gzip compression in zend framework website

查看:79
本文介绍了如何在zend Framework网站中设置gzip压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是zend的新手.我已经使用zend框架开发了一个网站.现在,我想在我的网站中设置gzip压缩.您能指导我明智地实现这一点吗?

I am new to zend. I have developed a website using zend framework. Now, I want to set gzip compression in my website. Would you please guide me step wise to implement this.

先谢谢了. 卡马尔·阿罗拉(Kamal Arora)

Thanks in advance. kamal Arora

推荐答案

我用您的技巧为zend framework 2(zf2)制作了

I made for zend framework 2 (zf2) with your tip

public function onBootstrap(MvcEvent $e)
{
    $eventManager = $e->getApplication()->getEventManager();
    $eventManager->attach("finish", array($this, "compressOutput"), 100);
}

public function compressOutput($e) 
{
    $response = $e->getResponse();
    $content = $response->getBody();
    $content = str_replace("  ", " ", str_replace("\n", " ", str_replace("\r", " ", str_replace("\t", " ", $content))));

    if(@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)
    {
        header('Content-Encoding: gzip');
        $content = gzencode($content, 9);
    }

    $response->setContent($content);
}

这篇关于如何在zend Framework网站中设置gzip压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆