Title: Use PHP4 to accelerate network transmission.
/***************************************
* * 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 has
* * 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 would 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 ' .
* *------------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
";
}
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"). "
";
$Error _msg. = "Remote-address:". $REMOTE _addr.
" ";
Mail (' your@none.net ', "User has x-gzip OUTP
UT 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 " ";
$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,0x
00,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"). " ";
$Error _msg. = "Remote-address:". $REMOTE _addr. " ";
Mail (' your@none.net ', "User can not use gzip output
in file $PHP _self!!! ", $Error _msg);
Exit
}
}
?>
http://www.bkjia.com/PHPjc/316832.html www.bkjia.com true http://www.bkjia.com/PHPjc/316832.html techarticle title: Use PHP4 to accelerate network transmission./*************************************** * * Title ...: PHP4 HTTP Compression Speeds up the W EB * * Version ...: 1.10 * * Author .....