使用 php4 加速 web 传输


Posted in PHP onOctober 09, 2006

<?
/***************************************
** Title.........: PHP4 HTTP Compression Speeds up the Web
** Version.......: 1.10
** Author........: catoc <catoc@163.net>
** Filename......: gzdoc.php
** Last changed..: 25/08/2000
** Requirments...: PHP4 >= 4.0.1
** PHP was configured with --with-zlib[=DIR]
** Notes.........: Dynamic Content Acceleration compresses
** the data transmission data on the fly
** code by sun jin hu (catoc) <catoc@163.net>
** Most newer browsers since 1998/1999 have
** been equipped to support the HTTP 1.1
** standard known as "content-encoding."
** Essentially the browser indicates to the
** server that it can accept "content encoding"
** and if the server is capable it will then
** compress the data and transmit it. The
** browser decompresses it and then renders
** the page.
** Useage........:
** No space before the beginning of the first '<?' tag.
** ------------Start of file----------
** |<?
** | include('gzdoc.php');
** | print "Start output !!";
** |?>
** |<HTML>
** |... the page ...
** |</HTML>
** |<?
** | gzdocout();
** |?>
** -------------End of file-----------
***************************************/
ob_start();
ob_implicit_flush(0);
function GetHeader(){
$headers = getallheaders();
while (list($header, $value) = each($headers)) {
$Message .= "$header: $value<br>\n";
}
return $Message;
}
function CheckCanGzip(){
global $HTTP_ACCEPT_ENCODING, $PHP_SELF, $Wget, $REMOTE_ADDR, $S_UserName;
if (connection_timeout() || connection_aborted()){
return 0;
}
if ((strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'gzip')) || $Wget == 'Y'){
if (strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'x-gzip')){
$ENCODING = "x-gzip";
$Error_Msg = str_replace('<br>','',GetHeader());
$Error_Msg .= "Time: ".date("Y-m-d H:i:s")."\n";
$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR."\n";
//mail('your@none.net', "User have x-gzip output in file $PHP_SELF!!!", $Error_Msg);
}else{
$ENCODING = "gzip";
}
return $ENCODING;
}else{
return 0;
}
}
function GzDocOut(){
global $PHP_SELF, $CatocGz, $REMOTE_ADDR, $S_UserName;
$ENCODING = CheckCanGzip();
if ($ENCODING){
print "\n<!-- Use compress $ENCODING -->\n";
$Contents = ob_get_contents();
ob_end_clean();
if ($CatocGz == 'Y'){
print "Not compress lenth: ".strlen($Contents)."<BR>";
print "Compressed lenth: ".strlen(gzcompress($Contents))."<BR>";
exit;
}else{
header("Content-Encoding: $ENCODING");
}
print pack('cccccccc',0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00);
$Size = strlen($Contents);
$Crc = crc32($Contents);
$Contents = gzcompress($Contents);
$Contents = substr($Contents, 0, strlen($Contents) - 4);
print $Contents;
print pack('V',$Crc);
print pack('V',$Size);
exit;
}else{
ob_end_flush();
$Error_Msg = str_replace('<br>','',GetHeader());
$Error_Msg .= "Time: ".date("Y-m-d H:i:s")."\n";
$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR."\n";
//mail('your@none.net', "User can not use gzip output in file $PHP_SELF!!!", $Error_Msg);
exit;
}
}
?>

PHP 相关文章推荐
如何正确理解PHP的错误信息
Oct 09 PHP
php中关于codeigniter的xmlrpc的类在进行数据交换时的类型问题
Jul 03 PHP
对淘宝URL中ID提取的PHP代码
Sep 01 PHP
PHP遍历并打印指定目录下所有文件实例
Feb 10 PHP
PHP中date与gmdate的区别及默认时区设置
May 12 PHP
ThinkPHP调试模式与日志记录概述
Aug 22 PHP
Zend Framework过滤器Zend_Filter用法详解
Dec 09 PHP
php魔法函数与魔法常量使用介绍
Jul 23 PHP
PHP中一个有趣的preg_replace函数详解
Aug 15 PHP
PHP实现简易计算器功能
Aug 28 PHP
php实现微信分享朋友链接功能
Feb 18 PHP
微信公众平台开发教程①获取用户Openid及个人信息图文详解
Apr 10 PHP
php 中include()与require()的对比
Oct 09 #PHP
php生成WAP页面
Oct 09 #PHP
让你同时上传 1000 个文件 (一)
Oct 09 #PHP
让你同时上传 1000 个文件 (二)
Oct 09 #PHP
一个可以删除字符串中HTML标记的PHP函数
Oct 09 #PHP
利用static实现表格的颜色隔行显示
Oct 09 #PHP
PHP 和 XML: 使用expat函数(三)
Oct 09 #PHP
You might like
使用PHP实现密保卡功能实现代码&amp;lt;打包下载直接运行&amp;gt;
2011/10/09 PHP
PHP 提取图片img标记中的任意属性的简单实例
2013/12/10 PHP
[原创]php token使用与验证示例【测试可用】
2017/08/30 PHP
ExtJS Grid使用SimpleStore、多选框的方法
2009/11/20 Javascript
js实现表格字段排序
2014/02/19 Javascript
javascript中 try catch用法
2015/08/16 Javascript
基于javascript如何传递特殊字符
2015/11/30 Javascript
Bootstrap导航条可点击和鼠标悬停显示下拉菜单的实现代码
2016/06/23 Javascript
JS在Chrome浏览器中showModalDialog函数返回值为undefined的解决方法
2016/08/03 Javascript
微信小程序实现皮肤功能(夜间模式)
2017/06/18 Javascript
浅谈Node.js CVE-2017-14849 漏洞分析(详细步骤)
2017/11/10 Javascript
解决layui上传文件提示上传异常,实际文件已经上传成功的问题
2018/08/19 Javascript
JS/jQuery实现简单的开关灯效果【案例】
2019/02/19 jQuery
深入理解redux之compose的具体应用
2020/01/12 Javascript
Python随机生成彩票号码的方法
2015/03/05 Python
在Django框架中编写Context处理器的方法
2015/07/20 Python
浅谈python中scipy.misc.logsumexp函数的运用场景
2016/06/23 Python
Python django实现简单的邮件系统发送邮件功能
2017/07/14 Python
Python温度转换实例分析
2018/01/17 Python
Python sklearn KFold 生成交叉验证数据集的方法
2018/12/11 Python
Pyinstaller打包Scrapy项目的实现步骤
2020/09/22 Python
Python爬虫之Selenium鼠标事件的实现
2020/12/04 Python
python爬取抖音视频的实例分析
2021/01/19 Python
使用CSS变量实现炫酷惊人的悬浮效果
2019/04/26 HTML / CSS
CSS3实现线性渐变用法示例代码详解
2020/08/07 HTML / CSS
说一下Linux下有关用户和组管理的命令
2016/01/04 面试题
会计电算化大学生职业规划书
2014/02/05 职场文书
三分钟演讲稿范文
2014/04/24 职场文书
安全宣传标语
2014/06/10 职场文书
2015年大学班长个人工作总结
2015/04/24 职场文书
永远是春天观后感
2015/06/12 职场文书
高三数学复习备考教学反思
2016/02/18 职场文书
导游词之宿迁乾隆行宫
2019/10/15 职场文书
Mysql 设置boolean类型的操作
2021/06/04 MySQL
HTML中的表单元素介绍
2022/02/28 HTML / CSS
CSS SandBox应用场景及常见问题
2022/06/25 HTML / CSS