使用php4加速网络传输


Posted in PHP onOctober 09, 2006

标 题: 使用php4加速网络传输。

<?
/***************************************
** 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> ";
        }
        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")."
";
                        $Error_Msg .= "Remote-Address: ".$REMOTE_ADDR.
" ";
                        //mail('your@none.net', "User have x-gzip outp
ut 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 " <!-- Use compress $ENCODING --> ";
                $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,0x
00,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")." ";
                $Error_Msg .= "Remote-Address: ".$REMOTE_ADDR." ";
                //mail('your@none.net', "User can not use gzip output  
in file $PHP_SELF!!!", $Error_Msg);
                exit;
        }
}
?>

PHP 相关文章推荐
PHP获取类中常量,属性,及方法列表的方法
Apr 09 PHP
PHP的单引号和双引号 字符串效率
May 27 PHP
php Smarty初体验二 获取配置信息
Aug 08 PHP
php 广告调用类代码(支持Flash调用)
Aug 11 PHP
用PHP写的基于Memcache的Queue实现代码
Nov 27 PHP
php密码生成类实例
Sep 24 PHP
再推荐十款免费的php开发工具
Nov 09 PHP
在WordPress中实现评论头像的自定义默认和延迟加载
Nov 24 PHP
php实现学生管理系统
Mar 21 PHP
php封装的smartyBC类完整实例
Oct 19 PHP
简单实现PHP留言板功能
Dec 21 PHP
php操作redis数据库常见方法实例总结
Feb 20 PHP
与数据库连接
Oct 09 #PHP
PHP新手上路(八)
Oct 09 #PHP
网络资源
Oct 09 #PHP
PHP中的正规表达式(一)
Oct 09 #PHP
PHP中的正规表达式(二)
Oct 09 #PHP
smtp邮件发送一例
Oct 09 #PHP
图片存储与浏览一例(Linux+Apache+PHP+MySQL)
Oct 09 #PHP
You might like
php采集神器cURL使用方法详解
2016/02/19 PHP
PHP使用imagick扩展实现合并图像的方法
2017/04/25 PHP
PHP实现的链式队列结构示例
2017/09/15 PHP
PHP实现动态创建XML文档的方法
2018/03/30 PHP
PHP7新增函数
2021/03/09 PHP
jQuery '行 4954 错误: 不支持该属性或方法' 的问题解决方法
2011/01/19 Javascript
JavaScript将相对地址转换为绝对地址示例代码
2013/07/19 Javascript
javascript获得网页窗口实际大小的示例代码
2013/09/21 Javascript
JS获取网页属性包括宽、高等等
2014/04/03 Javascript
原生js的弹出层且其内的窗口居中
2014/05/14 Javascript
jQuery中find()方法用法实例
2015/01/07 Javascript
jQuery操作JSON的CRUD用法实例
2015/02/25 Javascript
JS组件Bootstrap dropdown组件扩展hover事件
2016/04/17 Javascript
Bootstrap按钮组件详解
2016/04/26 Javascript
基于javascript实现表格的简单操作
2016/05/21 Javascript
BootStrap智能表单demo示例详解
2016/06/13 Javascript
js使用Replace结合正则替换重复出现的字符串功能示例
2016/12/27 Javascript
微信小程序 template模板详解及实例
2017/02/21 Javascript
input type=file 选择图片并且实现预览效果的实例
2017/10/26 Javascript
vue+iview+less+echarts实战项目总结
2018/02/22 Javascript
使用layui实现的左侧菜单栏以及动态操作tab项方法
2019/09/10 Javascript
js实现坦克大战游戏
2020/02/24 Javascript
Vue基本指令实例图文讲解
2021/02/25 Vue.js
python常用web框架简单性能测试结果分享(包含django、flask、bottle、tornado)
2014/08/25 Python
python使用cPickle模块序列化实例
2014/09/25 Python
Djang中静态文件配置方法
2015/07/30 Python
python3+PyQt5使用数据库窗口视图
2018/04/24 Python
代码实例讲解python3的编码问题
2019/07/08 Python
python中append实例用法总结
2019/07/30 Python
西班牙伏林航空公司:Vueling
2016/08/05 全球购物
英国鲜花递送:Blossoming Gifts
2020/07/10 全球购物
计算机工程学院个人求职信
2013/10/05 职场文书
学校安全检查制度
2014/01/27 职场文书
公司授权委托书范文
2014/08/02 职场文书
小学副班长竞选稿
2015/11/21 职场文书
仅仅使用 HTML/CSS 实现各类进度条的方式汇总
2021/11/11 HTML / CSS