Showing posts with label gzip. Show all posts
Showing posts with label gzip. Show all posts

Monday, August 8, 2011

Enable GZIP in PHP Application

Already i shown how to enable GZIP in YII Framework application, To enable GZIP in general PHP Application include the below code at the top of the document you want to gzip:

<?php
if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) && substr_count( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) )
 ob_start( 'ob_gzhandler' );
else
 ob_start();
?>

Enable GZIP in YII Application

Just add the following lines to protected/config/main.php,

add the below 2 lines after   'preload' => array('log'),

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