Use php4 to accelerate web transmission
Last Update:2014-05-19
Source: Internet
Author: User
& Lt ;? /*************************************** ** Title .........: PHP4HTTPCompressionSpeedsuptheWeb ** Version .......: 1.10 ** Author ........: catoc & lt; catoc@163.net & gt ;* /***************************************
** 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
** Server that it can accept "content encoding"
** And if the server is capable it will then
** Compress the data and transmit it.
** 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 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" ";
$ 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, 0 x, 0 x, 0 x, 0 x );
$ 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;
}
}
?>