Created
November 6, 2012 10:24
-
-
Save hengkiardo/4023901 to your computer and use it in GitHub Desktop.
Use GZip compression on your PHP files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$phpver = phpversion(); | |
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT; | |
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) ) { | |
if ( extension_loaded('zlib') ) { | |
ob_start('ob_gzhandler'); | |
} | |
} else if ( $phpver > '4.0' ) { | |
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') ) { | |
if ( extension_loaded('zlib') ) { | |
$do_gzip_compress = true; | |
ob_start(); | |
ob_implicit_flush(0); | |
header('Content-Encoding: gzip'); | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('gzip_header.php'); | |
include('your_template_file.php'); | |
include('gzip_footer.php'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment