使用 php4 加速 web 传输

所属分类: 网络编程 / PHP编程 阅读数: 1026
收藏 0 赞 0 分享
<?
/***************************************
** 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;
}
}
?>




更多精彩内容其他人还在看

JS操作XML中DTD介绍及使用方法分析

这篇文章主要介绍了JS操作XML中DTD介绍及使用方法,结合实例形式分析了DTD概念、原理及校验xml文档的相关操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

php常用日期时间函数实例小结

这篇文章主要介绍了php常用日期时间函数,结合实例形式总结分析了php日期时间相关的时间戳、格式化、时区获取与设置、时间戳转换与计算等相关操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

php无限极分类实现方法分析

这篇文章主要介绍了php无限极分类实现方法,结合实例形式分析了两种无限极分类的具体实现技巧与相关注意事项,需要的朋友可以参考下
收藏 0 赞 0 分享

用PHP做了一个领取优惠券活动的示例代码

这篇文章主要介绍了用PHP做了一个领取优惠券活动的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

php中isset与empty函数的困惑与用法分析

这篇文章主要介绍了php中isset与empty函数的困惑与用法,结合实例形式分析了php中isset与empty函数的功能、用法、区别及相关使用注意事项,需要的朋友可以参考下
收藏 0 赞 0 分享

php使用filter_var函数判断邮箱,url,ip格式示例

这篇文章主要介绍了php使用filter_var函数判断邮箱,url,ip格式,简单分析了php filter_var函数的功能、参数,并结合实例形式给出了filter_var函数判断邮箱,url,ip格式的相关操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

PHP面向对象程序设计子类扩展父类(子类重新载入父类)操作详解

这篇文章主要介绍了PHP面向对象程序设计子类扩展父类(子类重新载入父类)操作,涉及php面向对象方法重写与扩展相关操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

PHP中常用的三种设计模式详解【单例模式、工厂模式、观察者模式】

这篇文章主要介绍了PHP中常用的三种设计模式,结合实例形式详细分析了php单例模式、工厂模式与观察者模式概念、功能、相关使用技巧与操作注意事项,需要的朋友可以参考下
收藏 0 赞 0 分享

PHP如何实现阿里云短信sdk灵活应用在项目中的方法

这篇文章主要介绍了PHP如何实现阿里云短信sdk灵活应用在项目中的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

PHP反射学习入门示例

这篇文章主要介绍了PHP反射,简单描述了php反射的概念、原理,并结合实例形式分析了php反射的基本实现与使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多