使用 php4 加速 web 传输

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




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

php实现指定字符串中查找子字符串的方法

这篇文章主要介绍了php实现指定字符串中查找子字符串的方法,涉及php中strpos()函数查找字符串的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php去除字符串中空字符的常用方法小结

这篇文章主要介绍了php去除字符串中空字符的常用方法,实例分析了php中的trim()、ltrim()、rtrim()及chop()等函数的使用技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php通过rmdir删除目录的简单用法

这篇文章主要介绍了php通过rmdir删除目录的简单用法,实例分析了rmdir与mkdir函数的功能及使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php通过function_exists检测函数是否存在的方法

这篇文章主要介绍了php通过function_exists检测函数是否存在的方法,实例分析了php使用function_exists检测函数是否存在及调用的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php中ob_flush函数和flush函数用法分析

这篇文章主要介绍了php中ob_flush函数和flush函数用法,实例分析了ob_flush函数和flush函数的功能及相关的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php随机生成数字字母组合的方法

这篇文章主要介绍了php随机生成数字字母组合的方法,实例分析了php生成随机数及随机字母的相关技巧与用法,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php防止sql注入简单分析

这篇文章主要介绍了php防止sql注入的方法,简单分析了通过stripslashes及mysql_real_escape_string函数进行字符转移处理的技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

php制作文本式留言板

本文给大家分享的是使用php结合文本文件制作的留言板的代码,非常简单,实现了常用的功能,推荐给大家,有需要的小伙伴参考下吧。
收藏 0 赞 0 分享

php通过ksort()函数给关联数组按照键排序的方法

这篇文章主要介绍了php通过ksort()函数给关联数组按照键排序的方法,实例分析了php中ksort()函数的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

PHP 实现类似js中alert() 提示框

这篇文章主要介绍了PHP 实现类似js中alert() 提示框功能,非常的实用,这里推荐给大家,有需要的小伙伴来参考下,希望大家能喜欢。
收藏 0 赞 0 分享
查看更多