Gzip Web page compression can greatly improve the site access speed, for the site in foreign stations, this is an essential step, improve the speed of the Web page is very obvious, now we have a system to understand this gzip.
One, what is gzip
Gzip Concept
Gzip was originally created by Jean-loup gailly and Markadler for file compression for Unⅸ systems. We often use files with the. gz suffix in Linux, which are in gzip format. Nowadays it has become a very popular data compression format, or a file format, used on the Internet.
GZIP encoding on the HTTP protocol is a technique used to improve the performance of Web applications. High-traffic Web sites often use gzip compression technology to make users feel faster. This generally refers to the WWW server installed in a feature, when someone to access the server's website, the server of this feature will compress the content of the Web page to be displayed in the browser of the visiting computer. Generally, the plain text content can be compressed to 40% of the original size. So the transmission is fast, The effect is that when you click on the URL, it will show up quickly. This, of course, also increases the load on the server. This function module is installed in the general server.
Ii. What are the benefits of opening gzip?
When Gzip is turned on, the data exported to the user's browser is compressed, which reduces the amount of data transmitted over the network and improves the speed of browsing. Gzip can greatly accelerate the site. Sometimes the compression ratio is high to 80%, with a minimum of 40%.
This article mainly introduces PHP in 2 ways to open gzip compression, this article introduces the PHP configuration file and open method, PHP file opening method, the need for friends can refer to the following
PHP Configuration Modification Method:
The code is as follows:
Zlib.output_compression = on; turn on gzip function zlib.output_compression_level = 4;gzip compression level, 1~9, recommended 3~5;zlib.output_handler =; Gzip compression method, recommended note
PHP File Modification Method:
It is recommended to write at the beginning of the page, can write to the head public file
if (!headers_sent () &&//If the page header information is not output extension_loaded ("zlib") &&//and PHP has loaded 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 ');}