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');
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');
Under certain special circumstances, if an error message similar to the following appears:
output_handler "ob_gzhandler" conflicts with "zlib.output_compression"
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
That will solve the problem.