Php compression ob_gzhandler function has three methods _ PHP Tutorial

Source: Internet
Author: User
Php compresses the ob_gzhandler function in three ways. This article introduces three methods to compress the ob_gzhandler function in php. if you need to know the usage of the ob_gzhandler function, you can refer to this document. There are three methods to use the ob_gzhandler function in this article to introduce php to compress the ob_gzhandler function. if you need to know the usage of the ob_gzhandler function, you can refer to it.

There are three ways to use the ob_gzhandler function to compress php:

1. set output_handler = ob_gzhandler in php. ini.
2. add php_value output_handler ob_gzhandler to. htaccess.
3. add ob_start ('OB _ gzhandler') to the PHP file header ');

The first method is not feasible. The second method is good. once and for all, the effects of the first and second methods are the same, that is, compression of all php suffix files. Here I will mainly introduce the third method,
The CSS compression method is used as an example to compress style.css under the template.

1. copy style.cssin the Template directory and name it style.css. php.

Add this sentence to the top of style.css. php:

The code is as follows:

Add

The code is as follows:

2. modify the css connection in header. php as follows

Original:

The code is as follows:


Modified:

The code is as follows:


Now your CSS can be compressed by gzip.

JS can also use the same method, but the header added to xx. js. php should be like this:

The code is as follows:

(Remove when copying? Space before php)

Take a closer look at JS in the K2 topic, that is, add the ob_gzhandler function to the top after modifying the suffix to php.

The ob_gzhandler function can be used in three ways. if you need to know the usage of the ob_gzhandler function, please refer to it. There are three methods to use the ob_gzhandler function...

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.