使用 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入门速成(2)
Oct 09 PHP
php SQL防注入代码集合
Apr 25 PHP
php合并数组array_merge函数运算符加号与的区别
Oct 31 PHP
php expects parameter 1 to be resource, array given 错误
Mar 23 PHP
php 5.3.5安装memcache注意事项小结
Apr 12 PHP
IIS+fastcgi下PHP运行超时问题的解决办法详解
Jun 20 PHP
PHP session_start()问题解疑(详细介绍)
Jul 05 PHP
php把session写入数据库示例
Feb 26 PHP
php中adodbzip类实例
Dec 08 PHP
php实现跨域提交form表单的方法【2种方法】
Oct 17 PHP
laravel自定义分页效果
Jul 23 PHP
PHP pthreads v3在centos7平台下的安装与配置操作方法
Feb 21 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+java实现自动新闻滚动窗口
2006/10/09 PHP
php实现的MySQL通用查询程序
2007/03/11 PHP
用php过滤危险html代码的函数
2008/07/22 PHP
ThinkPHP3.1新特性之多层MVC的支持
2014/06/19 PHP
thinkPHP5项目中实现QQ第三方登录功能
2017/10/20 PHP
thinkPHP框架动态配置用法实例分析
2018/06/14 PHP
js实现浏览器的各种菜单命令比如打印、查看源文件等等
2013/10/24 Javascript
JQuery选择器、过滤器大整理
2015/05/26 Javascript
JavaScript上传文件时不用刷新页面方法总结(推荐)
2017/08/15 Javascript
实例解析ES6 Proxy使用场景介绍
2018/01/08 Javascript
Vue结合Video.js播放m3u8视频流的方法示例
2018/05/04 Javascript
详解基于vue-cli3.0如何构建功能完善的前端架子
2018/10/09 Javascript
Angular6 用户自定义标签开发的实现方法
2019/01/08 Javascript
vue cli 3.0 搭建项目的图文教程
2019/05/17 Javascript
JS回调函数 callback的理解与使用案例分析
2019/09/09 Javascript
node 标准输入流和输出流代码实例
2019/09/19 Javascript
Python常见格式化字符串方法小结【百分号与format方法】
2016/09/18 Python
python操作 hbase 数据的方法
2016/12/18 Python
python中urllib.unquote乱码的原因与解决方法
2017/04/24 Python
Python实现的下载网页源码功能示例
2017/06/13 Python
Python使用Selenium模块实现模拟浏览器抓取淘宝商品美食信息功能示例
2018/07/18 Python
python 模块导入问题汇总
2021/02/01 Python
Mavi牛仔裤美国官网:土耳其著名牛仔品牌
2016/09/24 全球购物
Agoda西班牙:全球特价酒店预订
2017/06/03 全球购物
柒牌官方商城:中国男装优秀品牌
2017/06/30 全球购物
西班牙拥有最佳品牌的动物商店:Animalear.com
2018/01/05 全球购物
校本教研工作方案
2014/01/14 职场文书
校园十大歌手策划书
2014/02/01 职场文书
四年级数学教学反思
2014/02/02 职场文书
期末学生评语大全
2014/04/24 职场文书
水利水电建筑施工应届生求职信
2014/07/04 职场文书
乡镇干部个人对照检查材料思想汇报
2014/10/04 职场文书
销售员工作检讨书(推荐篇)
2014/10/18 职场文书
关于法制教育的宣传语
2015/07/13 职场文书
节约用水广告语60条
2019/11/14 职场文书
Python使用Kubernetes API访问集群
2021/05/30 Python