Previously, I introduced how to use phpzlib extension to implement gzip compressed page output, mainly through the ob_gzhandler built-in function for gzip compressed output. In fact, php also provides the configuration method to enable the full-site gzip compressed output, mainly through php. the ini configuration file enables or disables the phpgzip configuration. The following describes the specific phpgzip compression configuration methods and precautions. Previously, I introduced how to use php zlib extension to implement gzip compressed page output, mainly through the ob_gzhandler built-in function for gzip compressed output, in fact, php also provides the configuration method to enable the full-site gzip compression output, mainly through php. the ini configuration file enables or disables the php gzip configuration. The following describes the specific php gzip compression configuration methods and precautions.
Preparations
1,Cannot find the php_zlib.dll file?
Zlib compression has been built into php since php4.3, so at least zlib does not need to be installed in Windows.
2,Install and build a php runtime environment
Since gzip configuration enabled in the php. ini configuration file cannot be used to compress php gzip output, it requires apache support. Therefore, we recommend that you install and build a php + apache + mysql runtime environment.
Php gzip configuration steps
I,Open the php. ini configuration file and find zlib. output_compression = Off.
1
2
|
Zlib. output_compression = Off
; Zlib. output_compression_level =-1 |
Change
1
2
|
Zlib. output_compression = On
Zlib. output_compression_level = 6 |
Php gzip Configuration Knowledge Point:
1. by default, php does not enable zlib for full-site compression Output. Instead, it uses the ob_gzhandler function for the page for compression Output. you can only select either of the two. Otherwise, an error is reported.
2. the default value of zlib. output_compression is Off. you can set it to On or output buffer size (4 k by default)
3. zlib. output_compression_level indicates the compression ratio. the default compression ratio is 6. the optional range is 1-9.-1 indicates disabling php zlib (gzip) compression.
II,Save the php. ini configuration file and restart the apache server.
III,Open the apache configuration file httpd. conf and configure the deflate_module
This step is the most critical step to enable the php gzip compressed output configuration. many users will say that I have enabled php. the php gzip configuration in the ini configuration file still does not implement php gzip compression, because apache is not loaded with deflate_module. the method is as follows:
1
|
# LoadModule deflate_module modules/mod_deflate.so |
Remove the starting # and restart apache.
OK. the page size after php gizp compression is shown below.
Size of the page configured for output after php gzip compression
We can see that the size of the output page of the phpinfo () function is 71.7 KB. By configuring php gzip, the size is compressed to 23.9 KB, and the php gzip compression effect is quite impressive.
So far, the configuration tutorial for php zlib (gzip) compression output is completed by modifying the php. ini configuration file.