Enable gzip Compression In PHP



Suppose you want to improve the speed of your website, it is a good to use PHP gzip compression for the frontend. Here in this post I am describing how to use gzip in your web page. This way you can easily include gzip compression on your web page. Put this code chunk on very top of your pages or create a page and insert all the code in it and include it on the header so that it will included on every pages.
<?php
if(extension_loaded('zlib')) 
	{ 
		ob_start('ob_gzhandler'); 
		$compressed = ''; 
	}
else { 
	ob_start(); 
	$compressed = ' not '; 
	}
 
echo 'This content is ' . $compressed . 'compressed with PHP gzip.';//replace next line with your code

ob_end_flush(); //put this in the end of your page
?>

Hope this will be helpful to someone else. Thanks and Enjoy the coding.