Speed Web Transfer with PHP 4
Last Update:2017-02-28
Source: Internet
Author: User
Web.?
/***************************************
* * 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 is 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'll then
* * Compress the data and transmit it. The
* * Browser decompresses it and then renders
* * the page.
* * Useage ...:
* * No Space before the beginning of the ' the ' the ' the ' ' 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 (the 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
}
}
?>