请教关于gzip,知道的请进阿! php manual LXXIII. Output Control Functionsexample:ibf/ipb 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个例子,利用gzcompress对页面进行压缩:<? function checkCanGzip() { global $HTTP_ACCEPT_ENCODING; if (headers_sent()) return 0; if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip"; if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip"; return 0; }function gzDocOut() { if ($encoding = checkCanGzip()) { $contents = ob_get_contents(); ob_end_clean(); header("Content-Encoding: ".$encoding); print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); $size = strlen($contents); $contents = gzcompress($contents, 9); $contents = substr($contents, 0, $size); print($contents);// print(pack('V', crc32($contents)));// print(pack('V', $size)); exit(); } else { ob_end_flush(); exit(); } } ob_start(); ob_implicit_flush(0); print("your stuff..."); gzDocOut();?>第一个函数对浏览器进行检验。第二个函数负责压缩。仔细揣摩一下 谢谢阿!还有吗?最好有详细的注解的,因为我接触PHP也刚不长的时间!还有上边的例子里边有压缩等级的吗? $contents = gzcompress($contents, 9);9即级别可以在0-9之间选择更改(0即不压缩) php数组问题,不好意思 刚刚描述有点问题 想作个屏幕右端标签可以展开的控件,如何下手?具体描述请看! php类的问题 IE6及一下输出xml为空,firefox下正常,怎么回事? 很郁闷的表格变形问题,大家帮忙看看~ smarttemplate为何编译后的文件老是会重新编译呢? 新手发问:如何能有效防止漏洞的产生? 高分送:如何实现网站浏览统计??? 小问题,大文章 急,在线等,如何连接和访问c:\a.mdb数据库,谢谢大侠们! 安装了apache和php4之后不能用的问题。 安装了apache和php4之后不能用的问题。
<?
function checkCanGzip() { global $HTTP_ACCEPT_ENCODING;
if (headers_sent()) return 0;
if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip";
return 0; }function gzDocOut() { if ($encoding = checkCanGzip()) {
$contents = ob_get_contents();
ob_end_clean();
header("Content-Encoding: ".$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$size = strlen($contents);
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $size);
print($contents);
// print(pack('V', crc32($contents)));
// print(pack('V', $size));
exit();
}
else {
ob_end_flush();
exit();
}
} ob_start();
ob_implicit_flush(0); print("your stuff..."); gzDocOut();?>
第一个函数对浏览器进行检验。
第二个函数负责压缩。仔细揣摩一下
9即级别
可以在0-9之间选择更改(0即不压缩)