Using php4 to accelerate network transfer _ PHP Tutorial

Source: Internet
Author: User
Use php4 to accelerate network transmission. Title: Use php4 to accelerate network transmission .? **************************************** * Title .........: PHP4HTTPCompressionSpeedsuptheWeb ** Version .......: 1.10 ** Author ..... question: 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 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 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 ('cccccccccccc', 0x1f, 0x8b, 0x08,0x00,0x00,0x00, 0x
X 00 );
$ 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;
}
}
?>





Exercise: use php4 to accelerate network transmission. ? /*************************************** ** Title .........: PHP4 HTTP Compression Speeds up the Web ** Version .......: 1.10 ** Author ........

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.