Php enables zlib to compress files

Source: Internet
Author: User
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, by default, both iis and apache only compress html static files. For PHP files, the module configuration is required. (Dynamic and Static Compression can be enabled in iis7.5 .)

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, by default, both iis and apache only compress html static files. For PHP files, the module configuration is required. (Dynamic and Static Compression can be enabled in iis7.5 .)

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, 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 implementation method is very simple. Open the php. ini file under the php Directory,

zlib.output_compression = Off;zlib.output_compression_level = -1
output_buffering = Off

Modify

zlib.output_compression =Onzlib.output_compression_level = 5
output_buffering = 4096

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 ~ The actual compression effect is not significant, but the cpu usage is a geometric increase.

Finally, you can view the request header and response header Through firebug. In fact, the gzip effect is displayed, or the gzip check tool of the webmaster also shows that gzip is valid.

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.