Www.wintermulberry.com accelerating web Transfer with PHP4

Source: Internet
Author: User
/***************************************
* * 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
\ 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 has 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 (' 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 ('
', ', 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 the gzip output in file $PHP _self!!!", $Error _msg);
Exit
}
}
?>

The above describes the www.wintermulberry.com use PHP4 to accelerate the web transfer, including the www.wintermulberry.com aspects of the content, I hope that the PHP tutorial interested in a friend to help.

  • Related Article

    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.