IIS6.0 enable Gzip and PHPGzip functions

Source: Internet
Author: User
Tags metabase
In a project, the project server mainly provides data, but when the data is too large, it is a waste of traffic and time. we will use Gzip for processing. I am using apache on the local machine, IIS6.0 on the server, and php, so I will share it here. GZIP compression for IIS

1. first, back up the IIS configuration file and copy C: \ Windows \ system32 \ inetsrv \ metabase. xml to another backup folder. c: \ Windows \ system32 \ inetsrv \ metabase. xml is the core configuration file of IIS. Once the file integrity is damaged, IIS cannot run normally, so it is necessary to reinstall the system.

2. start the Internet Information Service (IIS) manager in the Start menu, right-click the "website" attribute, open the "service" tab, and check the "HTTP compression" options. Set "temporary directory" and "maximum temporary directory capacity" as needed. After setting, click OK.

3. right-click "Web service extension" under "website" and add a new Web service extension. the extension can be set to "HTTP Compression" or other. Add "required Files": c: \ windows \ system32 \ inetsrv \ gzip. dll, check "set extension status to allow", and click "OK.

4. the steps below are a bit complex. if you are not sure you can understand them, you 'd better not try them. right-click the "local computer" attribute of "Internet information service, select "allow directly edit configuration database" and click OK.

5. run notepad C: \ Windows \ system32 \ inetsrv \ metabase. xml in the Start menu to open the metabase. xml file. make sure that the file has been backed up before any changes.

6. open metabase in a text editor. in xml format, you can use the search function to find "IIsCompressionScheme". there are three parts in total: deflate, gzip, and Parameters. deflate is also a compression format, but its performance is inferior to gzip. The deflate and gzip parameters must be modified.

HcDynamicCompressionLevel is used to set the compression ratio. the default value is 0 and the maximum value is 10. A slightly larger compressed file is generated at the lower compression level, but the overall impact on CPU and memory resources is small. The high compression level usually generates small compressed files, but it takes a lot of CPU time and memory. Some people say it is the most cost-effective to set it to 9.

HcFileExtensions is used to set the compressed static file extension. by default, it is htm, html, and txt. add the extension according to the website's own conditions. The most basic options are js and css. Note the original line feed format when adding.

HcScriptFileExtensions is used to set the compressed dynamic file extension. by default, it is asp, dll, and exe. you can add extensions as needed, similar to aspx and php. You can leave this item blank by default so that all dynamic responses are compressed. In addition, all unspecified static file types in HcFileExtensions are dynamically compressed and therefore not cached. Similarly, HcDoDynamicCompression must be set to true for dynamic compression.

PHP Gzip

The code is as follows:
/*
* Compressing data
*/
Public static function ob_gzip ($ content) // $ content is the page content to be compressed, or the biscuit raw material.
{
If (! Headers_sent () & // if the page header information has not been output
Extension_loaded ("zlib") & // and zlib extensions have been loaded into PHP
Strstr ($ _ SERVER ["HTTP_ACCEPT_ENCODING"], "gzip") // and the browser says it can accept GZIP pages
{
$ Content = gzencode ($ content. "OK", 9); // This page has been compressed "the annotation tag, and then compressed with the gzencode () function provided by zlib at the execution level of 9, the value range of this parameter is 0-9, 0 indicates no compression, 9 indicates the maximum compression, of course, the higher the compression level, the more expensive the CPU.

// Then use the header () function to send some header information to the browser, telling the browser that the 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 biscuit back to the workbench.
}

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.