Using the Mod_gzip module in Apache, we can use the GZIP compression algorithm to compress the Web content published by the Apache server before it is transferred to the client's browser. If the content is plain text, the effect is very obvious, approximately can be compressed to the original 30%-40%, so that the user's browsing speed greatly accelerated.
Gzip requires client browser support, most browsers currently support gzip, such as Ie,netscape,mozilla, so this method is worth a try. We can use the predefined variables $_server[' http_accept_encoding ' in PHP to determine if the client browser supports gzip.
gzip1.php
if (Ereg (gzip,$_server[http_accept_encoding])) { Browser support } else { Browser not supported, output other content } ? > |
Next we extend the above PHP program, using Ob_start (Ob_gzhandler) to compress the content of the Web page, buffer and send to the browser to support gzip, the browser will automatically extract the compressed content, display.
gzip2.php
Define (MAX,100);
if (Ereg (gzip,$_server[http_accept_encoding])) { The browser supports gzip, compressing content and buffering output Ob_start ("Ob_gzhandler"); $output =;
for ($i =0; $i <=MAX; $i + +) { $output. = "This was line $i"; } echo "browser supports gzip compression output"; Echo $output; } Else { Browser not supported, direct output for ($i =0; $i <=MAX; $i + +) { $output. = "This was line $i"; }
echo "Browser does not support gzip compression output"; Echo $output; } ? > |
The HTTP header information for a Web page that is generated by using gzip compression will have more information than a typical Web page:
Content-encoding:gzip content-length:270 |
If you would like more detailed information, please refer to the Mod_gzip Project homepage:
http://sourceforge.net/projects/mod-gzip/
Similarly, we can also use mod_deflate, the compression rate is slightly lower than the mod_gzip. Calling the ZIP function requires server memory, so use it sparingly, depending on your needs.
http://www.bkjia.com/PHPjc/508468.html www.bkjia.com true http://www.bkjia.com/PHPjc/508468.html techarticle using the Mod_gzip module in Apache, we can use the GZIP compression algorithm to compress the Web content published by the Apache server before it is transferred to the client's browser. If it is plain text ...