2 Methods for enabling gzip compression in PHP, 2 methods for phpgzip compression _ PHP Tutorial

Source: Internet
Author: User
Two methods for enabling gzip compression in PHP and two methods for phpgzip compression. Two methods for enabling gzip compression in PHP: phpgzip compression for two types of web pages, after enabling gzip compression, the size can be reduced by 20% ~ 90%, which can save a lot of bandwidth and reduce page response time. two gzip compression methods are enabled in PHP and two phpgzip compression methods are available.

After gzip compression is enabled, the size of the webpage can be reduced by 20% ~ 90%, which can save a lot of bandwidth, thus reducing the page response time and improving the user experience.

Php configuration change method:

The code is as follows:


Zlib. output_compression = On
; Enable the gzip function

Zlib. output_compression_level = 4
; Gzip compression level, 1 ~ 9. 3 ~ 5

; Zlib. output_handler =
; Gzip compression method. comments are recommended.

Php file modification method:

We recommend that you write it at the beginning of the page to a public file in the header.

The code is as follows:


If (! Headers_sent () & // if the page header information has not been output
Extension_loaded ("zlib") & // php has loaded the 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 ');
}

After gzip compression is enabled on the ghost web page, its volume can be reduced by 20% ~ 90%, can save a lot of bandwidth, thus reducing the page response time ,...

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.