使用 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 相关文章推荐
phpmyadmin里面导入sql语句格式的大量数据的方法
Jun 05 PHP
javascript,php获取函数参数对象的代码
Feb 03 PHP
深入理解PHP中的Session和Cookie
Jun 21 PHP
PHP快速按行读取CSV大文件的封装类分享(也适用于其它超大文本文件)
Apr 10 PHP
PHP实现通过正则表达式替换回调的内容标签
Jun 15 PHP
33道php常见面试题及答案
Jul 06 PHP
PHP实现简单的新闻发布系统实例
Jul 28 PHP
Yii中的cookie的发送和读取
Jul 27 PHP
PHP 7.1新特性的汇总介绍
Dec 16 PHP
PHP操作MySQL中BLOB字段的方法示例【存储文本与图片】
Sep 15 PHP
简单实用的PHP文本缓存类实例
Mar 22 PHP
PHP实现单文件、多个单文件、多文件上传函数的封装示例
Sep 02 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通过文件头检测文件类型通用代码类(zip,rar等)
2010/10/19 PHP
通过php快速统计某个数据库中每张表的数据量
2012/09/04 PHP
php支持中文字符串分割的函数
2015/05/28 PHP
CodeIgniter框架钩子机制实现方法【hooks类】
2018/08/21 PHP
基于jquery的表头固定的若干方法
2011/01/27 Javascript
JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
2011/07/04 Javascript
用Javascript评估用户输入密码的强度实现代码
2011/11/30 Javascript
用js获取电脑信息(是使用与IE浏览器)
2013/01/15 Javascript
Javascript 遍历页面text控件详解
2014/01/06 Javascript
Node.js中child_process实现多进程
2015/02/03 Javascript
nodejs实现获取当前url地址及url各种参数值
2015/06/25 NodeJs
很棒的js选项卡切换效果
2016/07/15 Javascript
基于JS实现发送短信验证码后的倒计时功能(无视页面刷新,页面关闭不进行倒计时功能)
2016/09/02 Javascript
javascript对浅拷贝和深拷贝的详解
2016/10/14 Javascript
原生JS实现圆环拖拽效果
2017/04/07 Javascript
jQuery获取复选框选中的当前行的某个字段的值
2017/09/15 jQuery
深入掌握 react的 setState的工作机制
2017/09/27 Javascript
纯js+css实现在线时钟
2020/08/18 Javascript
vue iview 隐藏Table组件里的某一列操作
2020/11/13 Javascript
python采用getopt解析命令行输入参数实例
2014/09/30 Python
详解python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
2017/06/23 Python
django开发post接口简单案例,获取参数值的方法
2018/12/11 Python
用vue.js组件模拟v-model指令实例方法
2019/07/05 Python
Python 离线工作环境搭建的方法步骤
2019/07/29 Python
Python如何实现动态数组
2019/11/02 Python
深入分析python 排序
2020/08/24 Python
特步官方商城:Xtep
2017/03/21 全球购物
Nayomi官网:沙特阿拉伯王国睡衣和内衣品牌
2020/12/19 全球购物
测量实习生自我鉴定
2013/09/19 职场文书
护士实习鉴定范文
2013/12/22 职场文书
军训学生自我鉴定
2014/02/12 职场文书
《夸父追日》教学反思
2014/02/26 职场文书
高中生个性发展自我评价
2015/03/09 职场文书
家庭贫困证明
2015/06/16 职场文书
Django分页器的用法你都了解吗
2021/05/26 Python
详解thinkphp的Auth类认证
2021/05/28 PHP