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;
}
?>
http://www.bkjia.com/PHPjc/371540.htmlwww.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...