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

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

问题描述

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

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

它实际上在做什么??

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或none,具体取决于浏览器.

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天全站免登陆