php php|php4,使用 php4 加速 web 传输

使用 php4 加速 web 传输

更新时间:2006年10月09日 00:00:00   作者:

/***************************************

** Title.........: PHP4 HTTP Compression Speeds up the Web

** Version.......: 1.10

** Author........: catoc

** 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)

** 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 !!";

** |?>

** |

** |... the page ...

** |

** |

** | gzdocout();

** |?>

** -------------End of file-----------

***************************************/

ob_start();

ob_implicit_flush(0);

function GetHeader(){

$headers = getallheaders();

while (list($header, $value) = each($headers)) {

$Message .= "$header: $value
\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('
','',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\n";

$Contents = ob_get_contents();

ob_end_clean();

if ($CatocGz == 'Y'){

print "Not compress lenth: ".strlen($Contents)."
";

print "Compressed lenth: ".strlen(gzcompress($Contents))."
";

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('
','',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;

}

}

?>

相关文章

1a1b05c64693fbf380aa1344a7812747.png

PHP和Mysqlweb应用开发核心技术-第1部分 Php基础-1开始了解php,想学习php的朋友可以看下,比较基础的知识。2011-07-07

4f55910a645b073bc4fc65dc10dc14bd.png

PHP5 安装方法...2007-01-01

0ea3c7666119d5615e582f823fb3fad6.png

什么是PEAR?(第二篇)

第三章

▉ 3-1 PEAR套件(Package)的资讯2009-03-03

4f96a78db829b1556ff16de21e013c7a.png

disk_free_space返回目录可用空间,这个可根据你当关硬盘的空间大小来判断2010-05-05

8cc1031babc6aff2319f1c6af8544aa0.png

Win9x/ME下Apache+PHP安装配置...2006-10-10

0c932a99bb7b6f23c937db507070cc7b.png

为了让PHP初学者少走一些弯路.所以突然神经恍惚.决定写下此文章.仅供PHP初学者参考.如有错误.还望指出.不甚感激.2010-10-10

cca732bf65a93ed2ec0ac80c638460fe.png

一个阿拉伯数字转中文数字的函数...2006-10-10

2d9f31f2af7b675a3d153d2b7f1035a7.png

PHP中GET变量的使用...2006-10-10

b452cee8ec5cd9e58ab98eba17281e59.png

今天小编就为大家分享一篇关于PHP count_chars()函数讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-02-02

f4838ec7e2d4da28e0b57d4e852dadd4.png

拼音码表的生成...2006-10-10

最新评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值