加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

探讨如何在PHP开启gzip页面压缩实例

发布时间:2020-12-13 06:21:34 所属栏目:PHP教程 来源:网络整理
导读:代码如下: if(Extension_Loaded('zlib')) Ob_Start('ob_gzhandler'); Header("Content-type: text/html"); ?> 无标题文档 for($i=0;$i echo 'Hello World!'; } ?> if(Extension_Loaded('zlib')) Ob_End_Flush(); ?> 代码如下: 无标题文档 ob_end_flush(); //

代码如下:
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;
}
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读