1. Open PHP Mode
Principle:
Header ("Content-encoding:gzip"); Echo gzencode (' Songjiankang ');
Example 1:
function Ob_gzip ($content)//$content is the content of the page to be compressed, or the cookie raw material { if (! headers_sent () && //If the page header information is not output extension_loaded ("zlib") && //and zlib extension has been loaded into PHP strstr ($_server["http_accept_encoding"], " GZIP) //And the browser says it can accept gzip page { $content = Gzencode ($content. "\n//This page has been compressed", 9); This page has been compressed "comment label, and then use the Gzencode () function provided by zlib to perform a level 9 compression, the parameter value range is 0-9,0 means no compression, 9 is the maximum compression, of course, the higher the compression the more CPU. //Then use the header () function to send some header information to the browser, telling the browser that this page has been compressed with gzip! header ("Content-encoding:gzip"); Header ("vary:accept-encoding"); Header ("Content-length:".) Strlen ($content)); } return $content; Return the compressed content, or send the compressed cookie back to the workbench. }ob_start (' Ob_gzip ');
Example 2:
#ob_gzhandler for PHP built-in functions, refer to Manual Ob_start (' Ob_gzhandler ');
2, Apache Way to open:
A. Open the module:
LoadModule deflate_module modules/mod_deflate.soloadmodule headers_module modules/mod_headers.so
Increase in b.httpd.conf
<ifmodule deflate_module> deflatecompressionlevel 9 addoutputfilterbytype deflate text/html Text/plain text/xml A Pplication/json application/xml addoutputfilter DEFLATE js css addoutputfilter includes. shtml. htm. Xml. php. html</ Ifmodule>
C. Restart the server
Original: http://www.cnblogs.com/siqi/p/4003421.html
"Go" apache/php turn on gzip compression