使用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和ACCESS写聊天室(三)
Oct 09 PHP
php htmlspecialchars加强版
Feb 16 PHP
PHP异步调用socket实现代码
Jan 12 PHP
修改ThinkPHP缓存为Memcache的方法
Jun 25 PHP
php中常量DIRECTORY_SEPARATOR用法深入分析
Nov 14 PHP
学习php设计模式 php实现合成模式(composite)
Dec 08 PHP
PHP中key和current,next的联合运用实例分析
Mar 29 PHP
Smarty模板变量调节器用法分析
May 23 PHP
CI框架使用composer安装的依赖包步骤与方法分析
Nov 21 PHP
PHP编程计算文件或数组中单词出现频率的方法
May 22 PHP
thinkphp框架类库扩展操作示例
Nov 26 PHP
Laravel中获取IP的真实地理位置
Apr 01 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
自制汽车收音机天线:收听广播的技巧和方法
2021/03/02 无线电
php命名空间学习详解
2014/02/27 PHP
Laravel中扩展Memcached缓存驱动实现使用阿里云OCS缓存
2015/02/10 PHP
摘自织梦CMS的HTTP文件下载类
2015/08/08 PHP
PHP编程文件处理类SplFileObject和SplFileInfo用法实例分析
2017/07/22 PHP
Laravel中10个有用的用法小结
2019/05/06 PHP
Linux下使用jq友好的打印JSON技巧分享
2014/11/18 Javascript
JS实现图片垂直居中显示小结
2016/12/13 Javascript
微信小程序 WebSocket详解及应用
2017/01/21 Javascript
Angular 4.x 路由快速入门学习
2017/05/03 Javascript
深入理解Vue生命周期、手动挂载及挂载子组件
2017/09/27 Javascript
使用webpack打包koa2 框架app
2018/02/02 Javascript
总结js函数相关知识点
2018/02/27 Javascript
Vue2.5学习笔记之如何在项目中使用和配置Vue
2018/09/26 Javascript
使用easyui从servlet传递json数据到前端页面的两种方法
2019/09/05 Javascript
微信小程序本地存储实现每日签到、连续签到功能
2019/10/09 Javascript
NodeJS http模块用法示例【创建web服务器/客户端】
2019/11/05 NodeJs
微信小程序如何获取地址
2019/12/24 Javascript
[02:28]PWL开团时刻DAY3——Ink Ice与DeMonsTer之间的勾心斗角
2020/11/03 DOTA
在Python中操作列表之list.extend()方法的使用
2015/05/20 Python
在Python的Flask框架中验证注册用户的Email的方法
2015/09/02 Python
安装ElasticSearch搜索工具并配置Python驱动的方法
2015/12/22 Python
python中logging库的使用总结
2017/10/18 Python
Django admin model 汉化显示文字的实现方法
2019/08/12 Python
英国文胸专家:AmpleBosom.com
2018/02/06 全球购物
有趣、实用和鼓舞人心的产品:Inspire Uplift
2019/11/05 全球购物
Timberland法国官网:购买靴子、鞋子、衣服、夹克和配饰
2019/11/30 全球购物
运动会解说词100字
2014/01/31 职场文书
大学生档案自我鉴定(2篇)
2014/10/14 职场文书
婚礼答谢礼品
2015/01/20 职场文书
出国留学单位推荐信
2015/03/26 职场文书
公司员工宿舍管理制度
2015/08/03 职场文书
同学会演讲稿
2019/04/02 职场文书
2019 入党申请书范文
2019/07/10 职场文书
毕业生自荐求职信书写的技巧
2019/08/26 职场文书
Python的代理类实现,控制访问和修改属性的权限你都了解吗
2022/03/21 Python