首页 > 编程 > PHP > 正文

使用php4加速网络传输

2019-09-08 23:11:44
字体:
来源:转载
供稿:网友
标 题: 使用php4加速网络传输。

<?
/***************************************
** 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
**/t/t PHP was configured with --with-zlib[=DIR]
** Notes.........: Dynamic Content Acceleration compresses
**/t/t the data transmission data on the fly
**/t/t code by sun jin hu (catoc) <catoc@163.net>
**/t/t Most newer browsers since 1998/1999 have
**/t/t been equipped to support the HTTP 1.1
**/t/t standard known as "content-encoding."
**/t/t Essentially the browser indicates to the
**/t/t server that it can accept "content encoding"
**/t/t and if the server is capable it will then
**/t/t compress the data and transmit it. The
**/t/t browser decompresses it and then renders
**/t/t the page.
** Useage........:
**/t/t No space before the beginning of the first '<?' tag
.
**/t/t ------------Start of file----------
**/t/t |<?
**/t/t | include('gzdoc.php');
**/t/t | print "Start output !!";
**/t/t |?>
**/t/t |<HTML>
**/t/t |... the page ...
**/t/t |</HTML>
**/t/t |<?
**/t/t | gzdocout();
**/t/t |?>
**/t/t -------------End of file-----------
***************************************/
ob_start();
ob_implicit_flush(0);
function GetHeader(){
/t$headers = getallheaders();
/twhile (list($header, $value) = each($headers)) {
/t/t$Message .= "$header: $value<br> ";
/t}
/treturn $Message;
}
function CheckCanGzip(){
/tglobal $HTTP_ACCEPT_ENCODING, $PHP_SELF, $Wget, $REMOTE_ADDR,  
$S_UserName;
/tif (connection_timeout() || connection_aborted()){
/t/treturn 0;
/t}
/tif ((strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'gzip')) || $Wget =
= 'Y'){
/t/tif (strpos('catoc'.$HTTP_ACCEPT_ENCODING, 'x-gzip')){

/t/t/t$ENCODING = "x-gzip";
/t/t/t$Error_Msg = str_replace('<br>','',GetHeader()
);
/t/t/t$Error_Msg .= "Time: ".date("Y-m-d H:i:s")."
";
/t/t/t$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR.
" ";
/t/t/t//mail('your@none.net', "User have x-gzip outp
ut in file $PHP_SELF!!!", $Error_Msg);
/t/t}else{
/t/t/t$ENCODING = "gzip";
/t/t}
/t/treturn $ENCODING;
/t}else{
/t/treturn 0;
/t}
}
function GzDocOut(){
/tglobal $PHP_SELF, $CatocGz, $REMOTE_ADDR, $S_UserName;
/t$ENCODING = CheckCanGzip();
/tif ($ENCODING){
/t/tprint " <!-- Use compress $ENCODING --> ";
/t/t$Contents = ob_get_contents();
/t/tob_end_clean();
/t/tif ($CatocGz == 'Y'){
/t/t/tprint "Not compress lenth: ".strlen($Contents)
."<BR>";
/t/t/tprint "Compressed lenth: ".strlen(gzcompress($
Contents))."<BR>";
/t/t/texit;
/t/t}else{
/t/t/theader("Content-Encoding: $ENCODING");
/t/t}
/t/tprint pack('cccccccc',0x1f,0x8b,0x08,0x00,0x00,0x00,0x
00,0x00);
/t/t$Size = strlen($Contents);
/t/t$Crc = crc32($Contents);
/t/t$Contents = gzcompress($Contents);
/t/t$Contents = substr($Contents, 0, strlen($Contents) - 4
);
/t/tprint $Contents;
/t/tprint pack('V',$Crc);
/t/tprint pack('V',$Size);
/t/texit;
/t}else{
/t/tob_end_flush();
/t/t$Error_Msg = str_replace('<br>','',GetHeader());
/t/t$Error_Msg .= "Time: ".date("Y-m-d H:i:s")." ";
/t/t$Error_Msg .= "Remote-Address: ".$REMOTE_ADDR." ";
/t/t//mail('your@none.net', "User can not use gzip output  
in file $PHP_SELF!!!", $Error_Msg);
/t/texit;
/t}
}
?>



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表