All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
PHP实现gzip页面压缩方法_[PHP教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/17 7:33:48 Browse times: 398 Comment times: 0

PHP实现gzip页面压缩方法_[PHP教程]


Head photo

Go homepage
Upload pictures
Write articles

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;
}
?>




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.