ThinkPHP3.1 New feature: page compression and output support _ php instance

Source: Internet
Author: User
ThinkPHP3.0 and earlier versions do not have the built-in page compression output function. manually adding code settings may conflict with the php configuration environment. The new ThinkPHP3.1 feature adds support for page compression output, for more information, see. most browsers currently support page compression. by compressing the output, the page size can be reduced by 30%, however, since neither version 3.0 nor earlier has the built-in page compression output function, developers generally need to add the following in the entry file:

ob_start('ob_gzhandler');

However, due to different server environments, sometimes this configuration conflicts with the zlib compression configuration in the php. ini file. ThinkPHP3.1 has built-in page compression and output functions. you do not need to manually add ob_gzhandler code, add OUTPUT_ENCODE configuration parameters, and support detection of zlib. output_compression.

By default, the framework compresses the page output and automatically detects zlib. output_compression configuration, if php. zlib in ini. when output_compression is enabled, the page is still compressed by page compression in the server environment.

There is only one line of related code:

if(!ini_get('zlib.output_compression') && C('OUTPUT_ENCODE')) ob_start('ob_gzhandler');

In some special environments, if an error message similar to the following occurs:

output_handler "ob_gzhandler" conflicts with "zlib.output_compression" 

This is generally because your server is configured with other compression methods, which leads to conflicts. in this case, you can manually disable OUTPUT_ENCODE, that is:

'OUTPUT_ENCODE'=>false

You can solve the problem.

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.