Home php教程 php手册 ThinkPHP3.1新特性之对页面压缩输出的支持

ThinkPHP3.1新特性之对页面压缩输出的支持

Jun 13, 2016 am 09:30 AM

目前大多数浏览器都已经支持页面的压缩输出,通过压缩输出,页面大小可以减少30%,但是由于3.0及以前的版本都没有内置页面压缩输出功能,所以一般来说,开发人员需要自己在入口文件中添加:

ob_start('ob_gzhandler');

Copy after login

但是由于服务器环境的不同,有时候这个配置会和php.ini文件中的zlib压缩配置冲突。而ThinkPHP3.1版则内置了页面压缩输出的功能,不再需要再手动添加ob_gzhandler代码,增加OUTPUT_ENCODE配置参数,并支持检测zlib.output_compression。

框架默认会进行页面压缩输出,并且会自动检测zlib.output_compression配置,如果php.ini里面zlib.output_compression是开启状态,则仍然以服务器环境的页面压缩方式进行页面压缩。

相关代码只有一行:

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

Copy after login

在个别特殊的环境下面,如果出现类似下面的错误提示:

output_handler "ob_gzhandler" conflicts with "zlib.output_compression" 

Copy after login

一般是由于你的服务器配置了其他的压缩方式导致冲突,这个时候你可以手动关闭OUTPUT_ENCODE,即:

'OUTPUT_ENCODE'=>false

Copy after login

就可以解决问题。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)