Two ways to enable gzip compression in PHP, 2 ways to enable gzip compression in php
After gzip compression is enabled on a web page, its size can be reduced by 20% to 90%, which can save a lot of bandwidth, thereby reducing page response time and improving user experience.
php configuration modification method:
Copy code The code is as follows:
zlib.output_compression = On
;Enable gzip function
zlib.output_compression_level = 4
;gzip compression level, 1~9, 3~5 recommended
;zlib.output_handler =
;gzip compression method, recommended comment
php file modification method:
It is recommended to write it at the beginning of the page, you can write to the header public file
Copy code The code is as follows:
if( !headers_sent() && // If the page header information has not been output yet
extension_loaded("zlib") && // And php has already loaded the zlib extension
strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")) //And the browser accepts GZIP
{
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '4');
}
http://www.bkjia.com/PHPjc/951231.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951231.htmlTechArticleTwo ways to enable gzip compression in PHP, phpgzip compression 2 types of web pages After turning on gzip compression, their size can be reduced 20%~90% smaller, which can save a lot of bandwidth, thereby reducing page response time,...