使用 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的开发框架的现状和展望
Mar 16 PHP
Ajax PHP简单入门教程代码
Apr 25 PHP
apache2.2.4+mysql5.0.77+php5.2.8安装精简
Apr 29 PHP
PHP中数字检测is_numeric与ctype_digit的区别介绍
Oct 04 PHP
ThinkPHP实现将SESSION存入MYSQL的方法
Jul 22 PHP
PHP生成短网址方法汇总
Jul 12 PHP
Yii2学习笔记之汉化yii设置表单的描述(属性标签attributeLabels)
Feb 07 PHP
ajax调用返回php接口返回json数据的方法(必看篇)
May 05 PHP
php支付宝系列之电脑网站支付
May 30 PHP
解决laravel 出现ajax请求419(unknown status)的问题
Sep 03 PHP
Laravel 实现在Blade模版中使用全局变量代替路径的例子
Oct 22 PHP
php模拟实现斗地主发牌
Apr 22 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
《雄兵连》《烈阳天道》真的来了
2020/07/13 国漫
PHP5/ZendEngine2的改进
2006/10/09 PHP
PHP4实际应用经验篇(8)
2006/10/09 PHP
PHP+JS无限级可伸缩菜单详解(简单易懂)
2007/01/02 PHP
有关PHP中MVC的开发经验分享
2012/05/17 PHP
使用PHP把HTML生成PDF文件的几个开源项目介绍
2014/11/17 PHP
PHP+shell脚本操作Memcached和Apache Status的实例分享
2016/03/11 PHP
简要剖析PHP的Yii框架的组件化机制的基本知识
2016/03/17 PHP
PHP中用Trait封装单例模式的实现
2019/12/18 PHP
经典的解除许多网站无法复制文字的绝招
2006/12/31 Javascript
jQuery+CSS 实现的超Sexy下拉菜单
2010/01/17 Javascript
用jquery与css打造个性化的单选框和复选框
2010/10/20 Javascript
解析URI与URL之间的区别与联系
2013/11/22 Javascript
如何使用PHP+jQuery+MySQL实现异步加载ECharts地图数据(附源码下载)
2016/02/23 Javascript
jQuery焦点图轮播插件KinSlideshow用法分析
2016/06/08 Javascript
Bootstrap基本组件学习笔记之列表组(11)
2016/12/07 Javascript
prototype与__proto__区别详细介绍
2017/01/09 Javascript
使用原生的javascript来实现轮播图
2017/02/24 Javascript
详解使用PM2管理nodejs进程
2017/10/24 NodeJs
动态加载权限管理模块中的Vue组件
2018/01/16 Javascript
Vue插槽原理与用法详解
2019/03/05 Javascript
从0搭建vue-cli4脚手架
2020/06/17 Javascript
python 中的list和array的不同之处及转换问题
2018/03/13 Python
python3 selenium自动化测试 强大的CSS定位方法
2019/08/23 Python
opencv3/C++实现视频背景去除建模(BSM)
2019/12/11 Python
Keras搭建自编码器操作
2020/07/03 Python
Marmot土拨鼠官网:美国专业户外运动品牌
2018/01/11 全球购物
ShellScript面试题一则-ShellScript编程
2014/06/24 面试题
酒店经理职责
2014/01/30 职场文书
银行求职自荐书
2014/06/25 职场文书
教师自查自纠材料
2014/10/14 职场文书
2014年行政后勤工作总结
2014/12/06 职场文书
教师个人师德总结
2015/02/06 职场文书
企业财务管理制度范本
2015/08/04 职场文书
扩展多台相同的Web服务器
2021/04/01 Servers
Win11 Build 25179预览版发布(附更新内容+ISO官方镜像下载)
2022/08/14 数码科技