Home > Backend Development > PHP Tutorial > 2 ways to enable gzip compression in PHP, 2 types of phpgzip compression_PHP tutorial

2 ways to enable gzip compression in PHP, 2 types of phpgzip compression_PHP tutorial

WBOY
Release: 2016-07-13 10:08:23
Original
968 people have browsed it

Two ways to enable gzip compression in PHP, 2 ways to enable gzip compression in php

After gzip compression is enabled on a web page, its size can be reduced by 20% to 90%, which can save a lot of bandwidth, thereby reducing page response time and improving user experience.

php configuration modification method:

Copy code The code is as follows:

zlib.output_compression = On
;Enable gzip function

zlib.output_compression_level = 4
;gzip compression level, 1~9, 3~5 recommended

;zlib.output_handler =
;gzip compression method, recommended comment

php file modification method:

It is recommended to write it at the beginning of the page, you can write to the header public file

Copy code The code is as follows:

if( !headers_sent() && // If the page header information has not been output yet
extension_loaded("zlib") && // And php has already loaded the zlib extension
strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")) //And the browser accepts GZIP
{
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '4');
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951231.htmlTechArticleTwo ways to enable gzip compression in PHP, phpgzip compression 2 types of web pages After turning on gzip compression, their size can be reduced 20%~90% smaller, which can save a lot of bandwidth, thereby reducing page response time,...
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