使用 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 相关文章推荐
PHPShop存在多个安全漏洞
Oct 09 PHP
一个PHP日历程序
Dec 06 PHP
php 进度条实现代码
Mar 10 PHP
检测png图片是否完整的php代码
Sep 06 PHP
PHP中foreach循环中使用引用要注意的地方
Jan 02 PHP
计算php页面运行时间的函数介绍
Jul 01 PHP
浅析php中常量,变量的作用域和生存周期
Aug 10 PHP
常用PHP封装分页工具类
Jan 14 PHP
利用PHP获取汉字首字母并且分组排序详解
Oct 22 PHP
thinkPHP框架实现的无限回复评论功能示例
Jun 09 PHP
PHP基于DateTime类解决Unix时间戳与日期互转问题【针对1970年前及2038年后时间戳】
Jun 13 PHP
Yii2.0框架模型多表关联查询示例
Jul 18 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木马攻击防御之道
2008/03/24 PHP
探讨方法的重写(覆载)详解
2013/06/08 PHP
你可能不知道PHP get_meta_tags()函数
2014/05/12 PHP
PHP实现求解最长公共子串问题的方法
2017/11/17 PHP
为Plesk PHP7启用Oracle OCI8扩展方法总结
2019/03/29 PHP
laravel 修改.htaccess文件 重定向public的解决方法
2019/10/12 PHP
一起来写段JS drag拖动代码
2010/12/09 Javascript
jQuery插件pagewalkthrough实现引导页效果
2015/07/05 Javascript
AngularJs中route的使用方法和配置
2016/02/04 Javascript
BootStrap glyphicons 字体图标实现方法
2016/05/01 Javascript
完美实现js拖拽效果 return false用法详解
2017/07/28 Javascript
Angular4 组件通讯方法大全(推荐)
2018/07/12 Javascript
ECharts地图绘制和钻取简易接口详解
2019/07/12 Javascript
微信小程序绑定手机号获取验证码功能
2019/10/22 Javascript
js实现GIF图片的分解和合成
2019/10/24 Javascript
JavaScript装箱及拆箱boxing及unBoxing用法解析
2020/06/15 Javascript
vue组件中实现嵌套子组件案例
2020/08/31 Javascript
[04:00]DOTA2解说界神雕侠侣 CJ第四天谷子现场过生日
2013/07/30 DOTA
举例讲解Python中的身份运算符的使用方法
2015/10/13 Python
利用python获取Ping结果示例代码
2017/07/06 Python
python基础while循环及if判断的实例讲解
2017/08/25 Python
浅谈使用Python内置函数getattr实现分发模式
2018/01/22 Python
python rsa实现数据加密和解密、签名加密和验签功能
2019/09/18 Python
浅析移动设备HTML5页面布局
2015/12/01 HTML / CSS
美国最大的城市服装和运动鞋零售商:Jimmy Jazz
2016/11/19 全球购物
strlen的几种不同实现方法
2013/05/31 面试题
财务人员的自我评价范文
2014/03/03 职场文书
新学期教师寄语
2014/04/02 职场文书
人力资源管理系自荐信
2014/05/31 职场文书
土建工程师岗位职责
2014/06/10 职场文书
公司采购主管岗位职责
2014/06/17 职场文书
2015年出纳个人工作总结
2015/04/02 职场文书
证券公司客户经理岗位职责
2015/04/09 职场文书
公司员工培训管理制度
2015/08/04 职场文书
用Python的绘图库(matplotlib)绘制小波能量谱
2021/04/17 Python
vue使用echarts实现折线图
2022/03/21 Vue.js