使用 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中在数据库中保存Checkbox数据(1)
Oct 09 PHP
PHP实现采集程序原理和简单示例代码
Mar 18 PHP
PHP header()函数使用详细(301、404等错误设置)
Apr 17 PHP
PHP遍历某个目录下的所有文件和子文件夹的实现代码
Jun 28 PHP
PHP中file_exists函数不支持中文名的解决方法
Jul 26 PHP
php中switch与ifelse的效率区别及适用情况分析
Feb 12 PHP
PHP会话处理的10个函数
Aug 11 PHP
php微信开发之带参数二维码的使用
Aug 03 PHP
利用php的ob缓存机制实现页面静态化方法
Jul 09 PHP
thinkphp5引入公共部分header、footer的方法详解
Sep 14 PHP
PHP检查URL包含特定字符串实例方法
Feb 11 PHP
PHP 99乘法表的几种实现代码
Oct 13 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
德生1994机评
2021/03/02 无线电
判断是否为指定长度内字符串的php函数
2010/02/16 PHP
php设计模式 Visitor 访问者模式
2011/06/28 PHP
php 搜索框提示(自动完成)实例代码
2012/02/05 PHP
使用PHP求两个文件的相对路径
2013/06/20 PHP
PHP session 会话处理函数
2016/06/06 PHP
js简单的弹出框有关闭按钮
2014/05/05 Javascript
详解jQuery Mobile自定义标签
2016/01/06 Javascript
浏览器检测JS代码(兼容目前各大主流浏览器)
2016/02/21 Javascript
JQuery在循环中绑定事件的问题详解
2016/06/02 Javascript
jQuery使用正则表达式限制文本框只能输入数字
2016/06/18 Javascript
plupload+artdialog实现多平台上传文件
2016/07/19 Javascript
jQuery实现侧浮窗与中浮窗切换效果的方法
2016/09/05 Javascript
bootstrap读书笔记之CSS组件(上)
2016/10/17 Javascript
从零学习node.js之详解异步控制工具async(八)
2017/02/27 Javascript
解决vue的变量在settimeout内部效果失效的问题
2018/08/30 Javascript
纯异步nodejs文件夹(目录)复制功能
2019/09/03 NodeJs
vue登录注册实例详解
2019/09/14 Javascript
[53:29]完美世界DOTA2联赛循环赛 DM vs Matador BO2第二场 11.04
2020/11/05 DOTA
python 正则式使用心得
2009/05/07 Python
python类参数self使用示例
2014/02/17 Python
Python中使用PyQt把网页转换成PDF操作代码实例
2015/04/23 Python
Python3字符串学习教程
2015/08/20 Python
详解Python编程中对Monkey Patch猴子补丁开发方式的运用
2016/05/27 Python
pyqt5之将textBrowser的内容写入txt文档的方法
2019/06/21 Python
Python 中@property的用法详解
2020/01/15 Python
python opencv 图像边框(填充)添加及图像混合的实现方法(末尾实现类似幻灯片渐变的效果)
2020/03/09 Python
浅析图片上传及canvas压缩的流程
2020/06/10 HTML / CSS
全球知名提供各类营养保健品的零售商:Vitamin Shoppe
2016/10/09 全球购物
会计岗位职责模板
2014/03/12 职场文书
园艺专业毕业生求职信
2014/09/02 职场文书
群众路线剖析材料(四风问题)
2014/10/08 职场文书
庆七一宣传标语
2014/10/08 职场文书
2015毕业生实习工作总结
2014/12/12 职场文书
分家协议书范本
2016/03/22 职场文书
OpenCV实现常见的四种图像几何变换
2022/04/01 Python