使用 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在不同页面间传递Json数据示例代码
Jun 08 PHP
php selectradio和checkbox默认选择的实现方法详解
Jun 29 PHP
PHP实现文件下载断点续传详解
Oct 15 PHP
php输出金字塔的2种实现方法
Dec 16 PHP
php查看网页源代码的方法
Mar 13 PHP
php生成圆角图片的方法
Apr 07 PHP
PHP简单获取网站百度搜索和搜狗搜索收录量的方法
Aug 23 PHP
PHP Header失效的原因分析及解决方法
Nov 16 PHP
php数组实现根据某个键值将相同键值合并生成新二维数组的方法
Apr 26 PHP
php7 list()、session及其他模块的修改实例分析
May 25 PHP
Apache+PHP+MySQL搭建PHP开发环境图文教程
Aug 06 PHP
PHP常量DIRECTORY_SEPARATOR原理及用法解析
Nov 10 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图片等比例缩放生成缩略图函数分享
2014/06/10 PHP
PHP调用C#开发的dll类库方法
2014/07/28 PHP
Yii数据读取与跳转参数传递用法实例分析
2016/07/12 PHP
PHP单例模式与工厂模式详解
2017/08/29 PHP
国外的为初学者写的JavaScript教程
2008/06/09 Javascript
Prototype 学习 工具函数学习($A方法)
2009/07/12 Javascript
Javascript load Page,load css,load js实现代码
2010/03/31 Javascript
Extjs入门之动态加载树代码
2010/04/09 Javascript
javascript不可用的问题探究
2013/10/01 Javascript
Jquery中国地图热点效果-鼠标经过弹出提示层信息的简单实例
2014/02/12 Javascript
JavaScript版经典游戏之扫雷游戏完整示例【附demo源码下载】
2016/12/12 Javascript
JavaScript数组去重的6个方法
2017/01/21 Javascript
JS使用面向对象技术实现的tab选项卡效果示例
2017/02/28 Javascript
老生常谈js-react组件生命周期
2017/05/02 Javascript
jQuery使用ajax_动力节点Java学院整理
2017/07/05 jQuery
解决vue点击控制单个样式的问题
2018/09/05 Javascript
node实现爬虫的几种简易方式
2019/08/22 Javascript
js实现圆形菜单选择器
2020/12/03 Javascript
Python3.2模拟实现webqq登录
2016/02/15 Python
Python 描述符(Descriptor)入门
2016/11/20 Python
Python中异常重试的解决方案详解
2017/05/05 Python
解决webdriver.Chrome()报错:Message:'chromedriver' executable needs to be in Path
2019/06/12 Python
python正则爬取某段子网站前20页段子(request库)过程解析
2019/08/10 Python
python实现ftp文件传输功能
2020/03/20 Python
Python实现捕获异常发生的文件和具体行数
2020/04/25 Python
使用Keras实现简单线性回归模型操作
2020/06/12 Python
Python基于gevent实现文件字符串查找器
2020/08/11 Python
详解HTML5常用的语义化标签
2019/09/27 HTML / CSS
Clarks鞋澳大利亚官方网站:Clarks Australia
2019/12/25 全球购物
技术总监岗位职责
2013/12/05 职场文书
电子商务专业求职信
2014/03/08 职场文书
网络编辑岗位职责
2014/03/18 职场文书
解决hive中导入text文件遇到的坑
2021/04/07 Python
CSS3实现的水平标题菜单
2021/04/14 HTML / CSS
pytorch训练神经网络爆内存的解决方案
2021/05/22 Python
WIN10使用IIS部署ftp服务器详细教程
2022/08/05 Servers