Home > Backend Development > PHP Tutorial > PHP implementation of gzip page compression method_PHP tutorial

PHP implementation of gzip page compression method_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:52:49
Original
792 people have browsed it

Example 1 (using PHP’s built-in compression function):

if(Extension_Loaded(’zlib’)) Ob_Start(’ob_gzhandler’);
Header("Content-type: text/html");
?>




Untitled Document


for($i=0;$i<10000;$i++){
echo ‘Hello World!’;
}
?>


if(Extension_Loaded(’zlib’)) Ob_End_Flush();
?>


Example 2 (self-written function):







Untitled Document






ob_end_flush();
//Compression function
function ob_gzip($content){
if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
$content = gzencode($content,9);
header("Content-Encoding: gzip");
header("Vary: Accept-Encoding");
header("Content-Length: ".strlen($content));
}
return $content;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371540.htmlTechArticleExample 1 (using PHP’s built-in compression function): ?PHP if(Extension_Loaded(zlib))Ob_Start(ob_gzhandler) ; Header(Content-type:text/html); ? !DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transiti...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template