使用 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生成月历代码
Jun 14 PHP
php中关于codeigniter的xmlrpc的类在进行数据交换时的类型问题
Jul 03 PHP
php实现单链表的实例代码
Mar 22 PHP
基于PHP服务端图片生成缩略图的方法详解
Jun 20 PHP
Drupal读取Excel并导入数据库实例
Mar 02 PHP
CI(CodeIgniter)框架中的增删改查操作
Jun 10 PHP
初识Laravel
Oct 30 PHP
php遍历树的常用方法汇总
Jun 18 PHP
php抓取并保存网站图片的实现代码
Oct 28 PHP
php实现的SSO单点登录系统接入功能示例分析
Oct 12 PHP
PHP读取目录树的实现方法分析
Mar 22 PHP
关于laravel-admin ueditor 集成并解决刷新的问题
Oct 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+DBM的同学录程序(4)
2006/10/09 PHP
Yii中Model(模型)的创建及使用方法
2015/12/28 PHP
深入解析PHP中SESSION反序列化机制
2017/03/01 PHP
jQuery.Autocomplete实现自动完成功能(详解)
2010/07/13 Javascript
基于jquery的3d效果实现代码
2011/03/23 Javascript
Three.js源码阅读笔记(Object3D类)
2012/12/27 Javascript
鼠标滑过出现预览的大图提示效果
2014/02/26 Javascript
jQuery实现的超链接提示效果示例【附demo源码下载】
2016/09/09 Javascript
AngularJS入门示例之Hello World详解
2017/01/04 Javascript
详解angularJS动态生成的页面中ng-click无效解决办法
2017/06/19 Javascript
理解Angular的providers给Http添加默认headers
2017/07/04 Javascript
基于jquery trigger函数无法触发a标签的两种解决方法
2018/01/06 jQuery
浅谈在vue中使用mint-ui swipe遇到的问题
2018/09/27 Javascript
node.js基于dgram数据报模块创建UDP服务器和客户端操作示例
2020/02/12 Javascript
Python运用于数据分析的简单教程
2015/03/27 Python
python3实现短网址和数字相互转换的方法
2015/04/28 Python
python实现矩阵打印
2019/03/02 Python
浅谈Python的条件判断语句if/else语句
2019/03/21 Python
Python多版本开发环境管理工具介绍
2019/07/03 Python
Python 操作 ElasticSearch的完整代码
2019/08/04 Python
opencv调整图像亮度对比度的示例代码
2019/09/27 Python
Python中有几个关键字
2020/06/04 Python
解决django migrate报错ORA-02000: missing ALWAYS keyword
2020/07/02 Python
Python实现一个简单的递归下降分析器
2020/08/01 Python
Python编写万花尺图案实例
2021/01/03 Python
Stutterheim瑞典:瑞典高级外套时装品牌
2019/06/24 全球购物
销售人员工作自我评价
2014/09/21 职场文书
2014年平安创建工作总结
2014/11/24 职场文书
2015年全国“爱牙日”宣传活动总结
2015/03/23 职场文书
幸福来敲门观后感
2015/06/04 职场文书
《所见》教学反思
2016/02/23 职场文书
PyCharm 安装与使用配置教程(windows,mac通用)
2021/05/12 Python
Spring Data JPA使用JPQL与原生SQL进行查询的操作
2021/06/15 Java/Android
MySQL Shell import_table数据导入的实现
2021/08/07 MySQL
Go中的条件语句Switch示例详解
2021/08/23 Golang
在ubuntu下安装go开发环境的全过程
2022/08/05 Golang