YII使用gzip压缩您的应用程序输出 [英] YII compress your application output using gzip

查看:198
本文介绍了YII使用gzip压缩您的应用程序输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是两个事件的好处是什么.

what is the benefit of below code that is two events.

它实际上在做什么??

what its actually doing ??

require_once($yii);
$app = Yii::createWebApplication($config);
Yii::app()->onBeginRequest = function($event)
{
  return ob_start("ob_gzhandler");
};

Yii::app()->onEndRequest = function($event)
{

return ob_end_flush();
};

$app->run();

请在我的应用程序中解释此代码的功能.以及对我有什么帮助?

please explain the function of this code in my application.what it does ?? and how can it help me ??

推荐答案

上面的代码缓冲内容并根据浏览器对其进行gzip压缩,而不是立即发送.

The above code buffers the content and gzips it according to browser, rather than sending it straight away.

Yii::app()->onBeginRequest = function($event)
{
return ob_start("ob_gzhandler");
};

上面的意思是,当请求开始时,它将缓冲内容,并且使用回调将内容设置为gzip,deflate或不设置,具体取决于浏览器.

The above means that when the requests starts, it will buffer the content, and using the callback will set the content as gzip,deflate or none, depending on browser.

Yii::app()->onEndRequest = function($event)
{
return ob_end_flush();
};

上面的代码只是意味着在请求结束时,它将输出缓冲区内容.

The above code simply means that at the end of the request, it will output the buffer contents.

这篇关于YII使用gzip压缩您的应用程序输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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