Application & nbsp; php4 & nbsp; acceleration & nbsp; web & nbsp; transmission

Source: Internet
Author: User
? /*************************************** ** Title .........: PHP4HTTPCompressionSpeedsuptheWeb ** Version .......: 1.10 ** Author ........: catoccatoc @ 16 /***************************************
** 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
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 ('cccccccccccc', 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'). '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;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.