使用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之第六天
Oct 09 PHP
Yii使用ajax验证显示错误messagebox的解决方法
Dec 03 PHP
phplot生成图片类用法详解
Jan 06 PHP
PHP实现链式操作的核心思想
Jun 23 PHP
54个提高PHP程序运行效率的方法
Jul 19 PHP
Yii2搭建后台并实现rbac权限控制完整实例教程
Apr 28 PHP
PHP十六进制颜色随机生成器功能示例
Jul 24 PHP
PHP实现的链式队列结构示例
Sep 15 PHP
PHP设计模式之工厂方法设计模式实例分析
Apr 25 PHP
PHP实现数组根据某个单元字段排序操作示例
Aug 01 PHP
yii2 url重写并隐藏index.php方法
Dec 10 PHP
PHP类的自动加载机制实现方法分析
Jan 10 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加密解密示例分享
2014/01/29 PHP
php启用sphinx全文搜索的实现方法
2014/12/24 PHP
php利用嵌套数组拼接与解析json的方法
2017/02/07 PHP
PHP编程实现计算抽奖概率算法完整实例
2017/08/09 PHP
jQuery操作input type=radio的实现代码
2012/06/14 Javascript
JS上传图片前的限制包括(jpg jpg gif及大小高宽)等
2012/12/19 Javascript
JavaScript立即执行函数的三种不同写法
2014/09/05 Javascript
JavaScript前端图片加载管理器imagepool使用详解
2014/12/29 Javascript
JS脚本根据手机浏览器类型跳转WAP手机网站(两种方式)
2015/08/04 Javascript
WordPress中利用AJAX异步获取评论用户头像的方法
2016/01/08 Javascript
jQuery图片切换动画特效
2016/11/02 Javascript
基于jQuery中ajax的相关方法汇总(必看篇)
2017/11/08 jQuery
sublime text配置node.js调试(图文教程)
2017/11/23 Javascript
如何根据业务封装自己的功能组件
2019/04/19 Javascript
JQuery表单元素取值赋值方法总结
2020/05/12 jQuery
[46:12]完美世界DOTA2联赛循环赛 DM vs Matador BO2第一场 11.04
2020/11/04 DOTA
结合Python的SimpleHTTPServer源码来解析socket通信
2016/06/27 Python
python 链接和操作 memcache方法
2017/03/04 Python
学生信息管理系统python版
2018/10/17 Python
python利用xlsxwriter模块 操作 Excel
2020/10/14 Python
JAVA程序员面试题
2012/10/03 面试题
师范应届生求职信
2013/11/15 职场文书
集团公司人力资源部岗位职责
2014/01/03 职场文书
办公设备采购方案
2014/03/16 职场文书
倡议书作文
2015/01/19 职场文书
工作违纪检讨书范文
2015/01/26 职场文书
艺术节开幕词
2015/01/28 职场文书
普宁寺导游词
2015/02/04 职场文书
2015年外贸业务员工作总结范文
2015/05/23 职场文书
心术观后感
2015/06/11 职场文书
工作证明书
2015/06/15 职场文书
教学副校长工作总结
2015/08/13 职场文书
护理工作心得体会
2016/01/22 职场文书
2016年十一促销广告语
2016/01/28 职场文书
SpringBoot生成License的实现示例
2021/06/16 Java/Android
Apache SkyWalking 监控 MySQL Server 实战解析
2022/09/23 Servers