使用 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 相关文章推荐
使用无限生命期Session的方法
Oct 09 PHP
php中通过smtp发邮件的类,测试通过
Jan 22 PHP
PHP下利用shell后台运行PHP脚本,并获取该脚本的Process ID的代码
Sep 19 PHP
七款最流行的PHP本地服务器分享
Feb 19 PHP
解析php下载远程图片函数 可伪造来路
Jun 25 PHP
php中读写文件与读写数据库的效率比较分享
Oct 19 PHP
php使用正则表达式获取图片url的方法
Jan 16 PHP
深入理解PHP中的empty和isset函数
May 26 PHP
PHP基于SimpleXML生成和解析xml的方法示例
Jul 17 PHP
PHP设计模式之模板方法模式定义与用法详解
Apr 02 PHP
php框架CodeIgniter主从数据库配置方法分析
May 25 PHP
ThinkPHP3.2.3框架邮件发送功能图文实例详解
Apr 23 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学习之字符串比较和查找
2011/04/17 PHP
让codeigniter与swfupload整合的最佳解决方案
2014/06/12 PHP
jQuery 名称冲突的解决方法
2011/04/08 Javascript
js操纵dom生成下拉列表框的方法
2014/02/24 Javascript
显示今天的日期js代码(阳历和农历)
2014/09/30 Javascript
Javascript学习笔记之数组的遍历和 length 属性
2014/11/23 Javascript
基于jquery实现图片上传本地预览功能
2016/01/08 Javascript
javascript中的作用域和闭包详解
2016/01/13 Javascript
socket.io学习教程之基础介绍(一)
2017/04/29 Javascript
Node.js开发第三方微信公众平台
2017/06/05 Javascript
JS实现合并json对象的方法
2017/10/10 Javascript
Vue2.0 axios前后端登陆拦截器(实例讲解)
2017/10/27 Javascript
移动前端图片压缩上传的实例
2017/12/06 Javascript
nodeJS服务器的创建和重新启动的实现方法
2018/05/12 NodeJs
从零开始封装自己的自定义Vue组件
2018/10/09 Javascript
jQuery轻量级表单模型验证插件
2018/10/15 jQuery
详解如何在Vue项目中导出Excel
2019/04/19 Javascript
seajs和requirejs模块化简单案例分析
2019/08/26 Javascript
vue请求服务器数据后绑定不上的解决方法
2019/10/30 Javascript
[01:20]PWL S2开团时刻第三期——团战可以输 蝙蝠必须死
2020/11/26 DOTA
python进阶教程之文本文件的读取和写入
2014/08/29 Python
Python中的高级数据结构详解
2015/03/27 Python
python基于物品协同过滤算法实现代码
2018/05/31 Python
Python将文本去空格并保存到txt文件中的实例
2018/07/24 Python
浅谈Pytorch中的torch.gather函数的含义
2019/08/18 Python
python 爬取小说并下载的示例
2020/12/07 Python
Pytorch之扩充tensor的操作
2021/03/04 Python
css3学习心得分享
2013/08/19 HTML / CSS
Stuarts London美国/加拿大:世界领先的独立男装零售商之一
2019/03/18 全球购物
俄罗斯金苹果网上化妆品和香水商店:Goldapple
2019/12/01 全球购物
华三通信H3C面试题
2015/05/15 面试题
儿科护理实习自我鉴定
2013/09/19 职场文书
校园报刊亭的创业计划书
2014/01/02 职场文书
离婚起诉状范本
2015/05/19 职场文书
2007年老电脑安装win11会怎么样? 网友实测win11在老电脑运行良好
2021/11/21 数码科技