无标题文档 for($i=0;$i ">
输入banner图图片脚本导航/分类

PHP实现gzip页面压缩方法_PHP教程

示例一(用php的内置压缩函数):

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




无标题文档


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


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


示例二(自写函数):







无标题文档






ob_end_flush();
//压缩函数
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.htmlTechArticle示例一(用php的内置压缩函数): ?PHP if(Extension_Loaded(zlib))Ob_Start(ob_gzhandler); Header(Content-type:text/html); ? !DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transiti...