Php simple open gzip compression method (zlib. output_compression) _ PHP Tutorial

Source: Internet
Author: User
Php simply enables the gzip compression method (zlib. output_compression ). Generally, after gzip compression is enabled for a page file, the size of the page file can be reduced by 60% ~ 90%. for text sites, you can save a lot of bandwidth and user waiting time. However, for iis, after gzip compression is enabled for page files, the size of the page files can be reduced by 60% ~ 90%. for text sites, you can save a lot of bandwidth and user waiting time. However, both iis and apache only compress html static files by default. for PHP files, the module configuration is required. (dynamic and static compression can be enabled in iis7.5 ), therefore, the effect of using php's own functions to reach gzip has become a reasonable demand.

The tutorial on the Internet is based on two methods: copy me and copy him. In fact, code should be added to every php page-of course, it can also be referenced by include, but it always seems a little troublesome.

In fact, the simplest 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; zlib. output_compression_level; and change-1 to 1 ~ The value of 5. In this way, the gzip effect of all php pages can be achieved without the need to modify the php files of the website separately-if there are many sites, it will save a lot of time.

Note the following points:

I. zlib. output_handler must be commented out because this parameter conflicts with the previous settings-the official statement.

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

3. the recommended parameter value of zlib. output_compression_level is 1 ~ 5 or 6, the actual compression effect is not significant, but the cpu usage is a geometric increase.

. View the request header and response header through firebug. In fact, the gzip effect is displayed.

The gzip detection tool of the webmaster site also shows that gzip is valid.

Bytes ~ 90%. for text sites, you can save a lot of bandwidth and user waiting time. However, whether it is iis or...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.