加速你的页面--数据压缩
最近偶的网站越来越慢,不是脚本执行时间慢,是网络传输速度慢。
知道http1.1支持gzip编码的数据,所以试试将自己的页面压缩压缩...
(在php.ini可以设置,直接输出为gzip编码,不过没试过)
上网搜到一个gzdoc.php,改了改,让大家共同琢磨琢磨。
ob_start();//打开输出缓冲
ob_implicit_flush(0);//
//*****************************************************************//
//函数名:canGzip()
//作用:检查客户浏览器是否支持gzip,x-gzip编码
//参数:
//返回值:支持的编码类型"gzip", "x-gzip", 返回false代表不支持
//*****************************************************************//
function canGzip()
{
//if (headers_sent() || connection_status)
//return false;
if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false)
return "gzip";
if (strpos('King'.$_SERVER["HTTP_ACCEPT_ENCODING"], 'x-gzip') !== false)
return "x-gzip";
return false;
}
//*****************************************************************//
//函数名:doGzipOut($level, $debug)
//作用:对输出缓冲的数据进行压缩并输出
//参数:$level代表压缩级别, 0 = 不压缩, 9 = 最大压缩率
// $debug代表是否输出调试信息, 1 = 输出, 0 = 不输出
//返回值:
//*****************************************************************//
function doGzipOut($level = 1, $debug = 0)
{
$ENCODING = canGzip();
if ($ENCODING)
{
echo "nn";
$contents = ob_get_contents();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
