How to enable #Gzip compression in Yii?
Updated November 23, 2013 ● 2,501 views
Yii channell is about Yii PHP Framework. Yii is a free, open-source Web application development framework written in PHP5 that promotes clean, dry design and encourages rapid development. It works to streamline your application development and helps to ensure an extremely efficient, extensible, and maintainable end product.
If you are a fellow Yii developer, join us! Do not hesitate to share your ideas. If you have a Yii product, you are welcome to share your creation here.
Check out Yii Framework official website.
Enabling Gzip compression in delivering your webpage will improve your sites performance. If you used Yii PHP Framework in developing your website, you only need two lines of code to enable Gzip compression.
In you main.php configuration file, just add the following code:
//GZIP compress
'onBeginRequest'=>create_function('$event', 'return ob_start("ob_gzhandler");'),
'onEndRequest'=>create_function('$event', 'return ob_end_flush();'),
Now, if you are using Google's PageSpeed Insight to get optimization suggestion for your website, it might still be saying that your page needs to enable compression. As per Google's PageSpeed Insights FAQ:
PageSpeed Insights' results are based on headers that were actually returned to your client, so if you are running the analysis on a client machine that is using such anti-virus software, or that sits behind an intermediate proxy server (many proxies are transparent, and you may not even be aware of a proxy intervening between your client and web server), they may be the cause of this issue.
You can use PageSpeed Insights Chrome extension to verify as suggested from PageSpeed Insights FAQ.
Awesome. Yii is the best PHP framwork out there. It's very easy to implement optimizations like this. Thanks!
master_yii · 11 years agopermalink · reply (0)