"Go" apache/php turn on gzip compression

Source: Internet
Author: User

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

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.