Speed Web Transfer with PHP 4

Source: Internet
Author: User
Tags date exit header mail pack strlen
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----------
* * |&LT;?
**                 | Include (' gzdoc.php ');
**                 | print "Start output!!";
**                 |? >
* * |* * | ... the page ...
* * |* * |&LT;?
**                 | 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
}
}
?>

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.