Two methods for enabling gzip compression in PHP and two methods for phpgzip compression. Two methods for enabling gzip compression in PHP: phpgzip compression for two types of web pages, after enabling gzip compression, the size can be reduced by 20% ~ 90%, which can save a lot of bandwidth and reduce page response time. two gzip compression methods are enabled in PHP and two phpgzip compression methods are available.
After gzip compression is enabled, the size of the webpage can be reduced by 20% ~ 90%, which can save a lot of bandwidth, thus reducing the page response time and improving the user experience.
Php configuration change method:
The code is as follows:
Zlib. output_compression = On
; Enable the gzip function
Zlib. output_compression_level = 4
; Gzip compression level, 1 ~ 9. 3 ~ 5
; Zlib. output_handler =
; Gzip compression method. comments are recommended.
Php file modification method:
We recommend that you write it at the beginning of the page to a public file in the header.
The code is as follows:
If (! Headers_sent () & // if the page header information has not been output
Extension_loaded ("zlib") & // php has 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 ');
}
After gzip compression is enabled on the ghost web page, its volume can be reduced by 20% ~ 90%, can save a lot of bandwidth, thus reducing the page response time ,...