Home > Backend Development > PHP Tutorial > ThinkPHP3.1 new feature: support for page compression output_PHP tutorial

ThinkPHP3.1 new feature: support for page compression output_PHP tutorial

WBOY
Release: 2016-07-13 10:24:28
Original
1086 people have browsed it

Currently, most browsers already support compressed output of pages. Through compressed output, the page size can be reduced by 30%. However, since versions 3.0 and earlier do not have built-in page compression output functions, generally speaking, developers need Add it yourself in the entry file:

ob_start('ob_gzhandler');

Copy after login

However, due to different server environments, sometimes this configuration will conflict with the zlib compression configuration in the php.ini file. ThinkPHP version 3.1 has a built-in page compression output function. It is no longer necessary to manually add ob_gzhandler code, add OUTPUT_ENCODE configuration parameters, and supports detection of zlib.output_compression.

The framework will perform page compression output by default, and will automatically detect the zlib.output_compression configuration. If zlib.output_compression is turned on in php.ini, the page compression method will still be used in the server environment.

There is only one line of relevant code:

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

Copy after login

Under certain special circumstances, if an error message similar to the following appears:

output_handler "ob_gzhandler" conflicts with "zlib.output_compression" 

Copy after login

Usually the conflict occurs because your server is configured with other compression methods. At this time, you can manually turn off OUTPUT_ENCODE, that is:

'OUTPUT_ENCODE'=>false

Copy after login

That will solve the problem.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825452.htmlTechArticleCurrently, most browsers already support compressed output of pages. Through compressed output, the page size can be reduced by 30%. However, since versions 3.0 and earlier do not have built-in page compression output function...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template