IIS6.0 Open gzip method and PHP gzip function sharing _php instance

Source: Internet
Author: User
Tags metabase

GZIP Compression for IIS

1. First back up the configuration file for IIS and copy C:\Windows\system32\inetsrv\metabase.xml to another backup folder. C:\Windows\system32\inetsrv\metabase.xml is the core configuration file for IIS, and the integrity of the file is corrupted, and IIS will not function properly, seriously requiring the system to be reinstalled.

2. Start the Internet Information Services (IIS) Manager in the Start menu, right-click the Web Site property, open the Services tab, and check the two options for HTTP compression. The temporary directory and temporary directory maximum capacity can be set as needed. Click OK when Setup is complete.

3. Right-click "Web Service Extensions" under "Web Site" to add a new Web service extension, complete with the extension "HTTP Compression" or anything else. "Required Files" add: C:\windows\system32\inetsrv\gzip.dll, and check "set extended status to allow", click OK when finished.

4. The following steps are somewhat complicated, if you do not have a certain grasp to understand, it is best not to try, right click on the "Internet Information Services," "Local Computer" property, check "Allow direct edit configuration database" and determine.

5. In the Start menu run Notepad C:\Windows\system32\inetsrv\metabase.xml, open the MetaBase.xml file, please reconfirm before any changes that the file has been backed up.

6. With a text editor to open MetaBase.xml, find the "IIsCompressionScheme", there are 3, are all together, respectively, deflate, gzip and parameters,deflate is also a compressed format, However, performance is inferior to gzip. Need to modify is deflate and gzip these two paragraphs, the parameters are basically the same, must be modified.

HcDynamicCompressionLevel is used to set the compression rate, the default is 0, the highest is 10. Low compression levels generate slightly larger compressed files, but have a smaller overall impact on CPU and memory resources. High compression levels typically generate smaller compressed files, but consume more CPU time and memory. It is said that set to 9 the highest cost-effective.

HcFileExtensions is used to set the compression of the static file name extension, the default is HTM, HTML, txt, according to the site's own situation to add extensions, the most basic is JS, CSS. Note the original newline format when adding.

HcScriptFileExtensions is used to set the compressed dynamic file name extension, the default is ASP, DLL and EXE, add the extension as needed, no outside of ASPX, PHP and so on. You can leave the default deletion of this item blank so that all dynamic responses are sent in a compressed manner. In addition, all static file types that are not specified in HcFileExtensions are dynamically compressed, and are therefore not put into the cache. Similarly, hcdodynamiccompression must be set to true for dynamic compression.

PHP Gzip

Copy Code code as follows:

/*
* Compress data
*/
public static function Ob_gzip ($content)//$content is the content of the page to compress, or the cookie material
{
if (!headers_sent () &&//If the page header information has not yet been exported
extension_loaded ("zlib") &&/and zlib extensions have been loaded into PHP
Strstr ($_server["http_accept_encoding"], "gzip")//and browser says it can accept gzip pages
{
$content = Gzencode ($content.) OK ", 9); This page has been compressed, and then the Gzencode () function provided with Zlib performs a compression of level 9, the range of which is 0-9,0 for no compression, 9 for maximum compression, and of course the higher the compression cost CPU.

Then use the header () function to send some header information to the browser, tell the browser 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.
}

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.