PHP simply turns on gzip compression method (zlib.output_compression)_PHP tutorial

WBOY
Release: 2016-07-21 15:12:39
Original
971 people have browsed it

Generally speaking, after turning on gzip compression of a page file, its size can be reduced by 60% to 90%. For text-based sites, it can save a lot of bandwidth and user waiting time. However, both iis and apache only compress HTML static files by default. PHP files require module configuration to support them (dynamic + static compression can also be enabled in iis7.5), so the effect of using PHP's own functions to achieve gzip has become a a reasonable request.

Basically, the tutorials on the Internet are copied by each other, and there are no more than two ways of writing: adding a head and a tail or a self-constructor function. In fact, every PHP page needs to add code - of course, you can also include references, but it always seems a little troublesome.

In fact, the easiest way is to open the php.ini file in the php directory, find zlib.output_compression = Off, and change it to zlib.output_compression = On,

Remove the ";" in front of "zlib.output_compression_level" and change the -1 behind to a value between 1 and 5. In this way, the gzip effect of all PHP pages can be achieved, and there is no need to modify the PHP files of the website separately - this will save a lot of time if there are many sites.

The following points need to be explained

1. ;zlib.output_handler must remain commented out because this parameter conflicts with the previous setting - official statement.

2. Generally, the cache is 4k (output_buffering = 4096).

3. The recommended parameter value for zlib.output_compression_level is 1~5. With 6, the actual compression effect will not improve much, but the CPU usage will increase geometrically.

点击查看原图

Figure 1. Check the request header and response header through firebug. In fact, the gzip effect has been displayed

点击查看原图

Figure 2. The webmaster’s gzip detection tool also shows that gzip is valid.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326646.htmlTechArticleGenerally speaking, after gzip compression is enabled on the page file, its size can be reduced by 60% to 90%. For text Such sites can save a lot of bandwidth and user waiting time. But whether it is iis or...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!