IIS6.0 turns on the Gzip method and PHP Gzip function sharing

  • 2021-06-28 12:01:59
  • OfStack

GZIP compression for IIS

1. First backup the IIS configuration file, copy C:\Windowssystem32\inetsrvmetabase.xml to another backup folder. C:\Windowssystem32inetsrvmetabase.xml is the core configuration file of IIS. The integrity of this file is 1 but damaged. IIS will not function properly and will need to be reinstalled seriously.

2. Start the Internet Information Service (IIS) Manager in the Start menu, right-click on the Site property, open the Service tab, and check the two options for HTTP Compression.Temporary Directory and Temporary Directory Maximum Capacity can be set up on your own.Click OK when setup is complete.

3. Right-click "Web Service Extension" under "Web Site" to add a new Web Service Extension with the extension "HTTP Compression" or something else.Required file "Add: c:windows32inetsrvgzip.dll, check"Set extension status to allow", and click OK when done.

4. The steps below are somewhat complicated. If you are not sure what you can understand, it is best not to try. Right-click on the "Local Computer" property of Internet Information Services, check "Allow direct editing of the configuration database" and confirm.

5. Run notepad C:Windowssystem32inetsrvmetabase.xml in the Start Menu to open the metabase.xml file. Please confirm that the file has been backed up again before making any changes.

6. Open metabase.xml in a text editor and use the lookup function to find "IIsCompressionScheme". There are three places, one for deflate, gzip and Parameters. deflate is also a compression format, but its performance is not as good as gzip.What needs to be modified are the deflate and gzip, which have the same parameters and need to be modified.

HcDynamicCompressionLevel is used to set the compression ratio, defaulting to 0 and up to 10.The low compression level produces a slightly larger compressed file, but has less overall impact on CPU and memory resources.High compression levels usually result in smaller compressed files, but use more CPU time and memory.Some people say that 9 is the best value for money.

HcFileExtensions is a static file extension used to set compression. By default, htm, html, txt, add extensions according to the site's own conditions, the most basic of which is js, css.Note the original line break format when adding.

HcScriptFileExtensions is a dynamic file extension used to set compression. By default, asp, dll and exe add extensions as needed, no more than aspx, php, etc.You can leave the default deletion of this item blank so that all dynamic responses are sent in a compressed fashion.All static file types not specified in HcFileExtensions will also be dynamically compressed and therefore not cached.Similarly, HcDoDynamicCompression must be set to true for dynamic compression.

PHP Gzip


/*
*  compressed data 
*/
public static function ob_gzip($content) // $content  Is the content of the page to be compressed, or biscuit ingredients 
{   
    if(    !headers_sent() && //  If the header information has not been output 
        extension_loaded("zlib") && //  And zlib Extension already loaded into PHP in 
        strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")) // And the browser says it's acceptable GZIP Page of  
    {
        $content = gzencode($content." OK",9); // This page has a compressed comment label, and then uses zlib Provided gzencode() Function execution level is 9 Compression, the range of values for this parameter is 0-9 , 0 Represents no compression, 9 Represents maximum compression, of course higher compression is more expensive CPU . 

        // Then use header() Function Send to Browser 1 Some header information tells the browser that the page is already in use GZIP Compressed! 
        header("Content-Encoding: gzip"); 
        header("Vary: Accept-Encoding");
        header("Content-Length: ".strlen($content));
    }
        return $content; // Return the compressed content, or send the compressed biscuits back to the workbench. 
}


Related articles: