<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gzip &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/gzip/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 10:21:58 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>Apache开启Gzip页面压缩功能(可大幅度提高网页浏览速度)</title>
		<link>https://www.mudbest.com/apache%e5%bc%80%e5%90%afgzip%e9%a1%b5%e9%9d%a2%e5%8e%8b%e7%bc%a9%e5%8a%9f%e8%83%bd%e5%8f%af%e5%a4%a7%e5%b9%85%e5%ba%a6%e6%8f%90%e9%ab%98%e7%bd%91%e9%a1%b5%e6%b5%8f%e8%a7%88%e9%80%9f%e5%ba%a6/</link>
					<comments>https://www.mudbest.com/apache%e5%bc%80%e5%90%afgzip%e9%a1%b5%e9%9d%a2%e5%8e%8b%e7%bc%a9%e5%8a%9f%e8%83%bd%e5%8f%af%e5%a4%a7%e5%b9%85%e5%ba%a6%e6%8f%90%e9%ab%98%e7%bd%91%e9%a1%b5%e6%b5%8f%e8%a7%88%e9%80%9f%e5%ba%a6/#comments</comments>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Mon, 04 Jun 2012 07:13:15 +0000</pubDate>
				<category><![CDATA[分享]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Gzip]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=1085</guid>

					<description><![CDATA[Apache默认是没有开启Gzip模块的，需要手动将其打开。 关于IIS6.0的GZIP开启方法与Apache ... <a title="Apache开启Gzip页面压缩功能(可大幅度提高网页浏览速度)" class="read-more" href="https://www.mudbest.com/apache%e5%bc%80%e5%90%afgzip%e9%a1%b5%e9%9d%a2%e5%8e%8b%e7%bc%a9%e5%8a%9f%e8%83%bd%e5%8f%af%e5%a4%a7%e5%b9%85%e5%ba%a6%e6%8f%90%e9%ab%98%e7%bd%91%e9%a1%b5%e6%b5%8f%e8%a7%88%e9%80%9f%e5%ba%a6/" aria-label="阅读 Apache开启Gzip页面压缩功能(可大幅度提高网页浏览速度)">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>Apache默认是没有开启Gzip模块的，需要手动将其打开。</p>
<p>关于IIS6.0的GZIP开启方法与Apache截然不同，虽然也是修改文件，但却有着实质性的差异。</p>
<p>首先需要打开与Gzip相关的模块。</p>
<p>1. httpd.conf中打开deflate_Module和headers_Module模块 <span id="more-1085"></span><br />
<a href="http://www.mudbest.com/1085.action/attachment/3333" rel="attachment wp-att-1099"><img fetchpriority="high" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2012/06/3333-505x430.jpg" alt="" title="3333" width="505" height="430" class="alignnone size-medium wp-image-1099" srcset="https://www.mudbest.com/wp-content/uploads/2012/06/3333-505x430.jpg 505w, https://www.mudbest.com/wp-content/uploads/2012/06/3333.jpg 612w" sizes="(max-width: 505px) 100vw, 505px" /></a><br />
2.在httpd.conf最下方增加以下代码(如图)：</p>
<p><a href="http://www.mudbest.com/1085.action/2-11" rel="attachment wp-att-1087"><img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2012/06/2-610x407.jpg" alt="" title="2" width="610" height="407" class="alignnone size-medium wp-image-1087" srcset="https://www.mudbest.com/wp-content/uploads/2012/06/2-610x407.jpg 610w, https://www.mudbest.com/wp-content/uploads/2012/06/2.jpg 838w" sizes="(max-width: 610px) 100vw, 610px" /></a></p>
<pre class="brush: plain; title: ; notranslate">
&lt;IfModule deflate_module&gt;
	SetOutputFilter DEFLATE
	#这里开始声明哪些不进行压缩
	SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI .(?:pdf|doc|ppt)$ no-gzip dont-vary
	#声明结束
	AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
	AddOutputFilterByType DEFLATE application/x-javascript
	#针对代理服务器设置
	&lt;IFModule headers_module&gt;
		Header append vary User-Agent
	&lt;/IFModule&gt;
&lt;/IfModule&gt;
</pre>
<p>当启用之后测试一下效果。</p>
<p>未Gzi启用前<br />
<a href="http://www.mudbest.com/1085.action/nogzip" rel="attachment wp-att-1089"><img decoding="async" src="http://www.mudbest.com/wp-content/uploads/2012/06/nogzip.jpg" alt="" title="nogzip" width="392" height="214" class="alignnone size-full wp-image-1089" /></a></p>
<p>启用Gzip之后<br />
<a href="http://www.mudbest.com/1085.action/yesgzip-2" rel="attachment wp-att-1091"><img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2012/06/yesgzip1.jpg" alt="" title="yesgzip" width="400" height="243" class="alignnone size-full wp-image-1091" /></a></p>
<p>可以明显看得出在启用前与启用后的差异，这也是优化了网络浏览速度的一种方法。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mudbest.com/apache%e5%bc%80%e5%90%afgzip%e9%a1%b5%e9%9d%a2%e5%8e%8b%e7%bc%a9%e5%8a%9f%e8%83%bd%e5%8f%af%e5%a4%a7%e5%b9%85%e5%ba%a6%e6%8f%90%e9%ab%98%e7%bd%91%e9%a1%b5%e6%b5%8f%e8%a7%88%e9%80%9f%e5%ba%a6/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>gzip解码函数gzdecode()</title>
		<link>https://www.mudbest.com/gzip%e8%a7%a3%e7%a0%81%e5%87%bd%e6%95%b0gzdecode/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Sun, 18 Sep 2011 07:08:07 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Gzip]]></category>
		<category><![CDATA[解码函数]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=797</guid>

					<description><![CDATA[最近采集土豆，发现土豆的页面貌似用了gzip，当使用file_get_contents()获取得到的是一些乱码 ... <a title="gzip解码函数gzdecode()" class="read-more" href="https://www.mudbest.com/gzip%e8%a7%a3%e7%a0%81%e5%87%bd%e6%95%b0gzdecode/" aria-label="阅读 gzip解码函数gzdecode()">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>最近采集土豆，发现土豆的页面貌似用了gzip，当使用file_get_contents()获取得到的是一些乱码，当时试着将页面的编码改来改去，但还是不行，想到了以前碰到类似的情况，好吧，果然。</p>
<p>分析：<br />
大概有2种情况，1是自身的页面编码，和获取的页面编码不一致。<br />
另外的一种情况就是，目标页面用了gzip技术。<br />
用以下的函数可解决这个问题：</p>
<p><span id="more-797"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

function gzdecode($data) {
	$len = strlen ( $data );
	if ($len &lt; 18 || strcmp ( substr ( $data, 0, 2 ), &quot;\x1f\x8b&quot; )) {
		return null; // Not GZIP format (See RFC 1952) 
	}
	$method = ord ( substr ( $data, 2, 1 ) ); // Compression method 
	$flags = ord ( substr ( $data, 3, 1 ) ); // Flags 
	if ($flags &amp; 31 != $flags) {
		// Reserved bits are set -- NOT ALLOWED by RFC 1952 
		return null;
	}
	// NOTE: $mtime may be negative (PHP integer limitations) 
	$mtime = unpack ( &quot;V&quot;, substr ( $data, 4, 4 ) );
	$mtime = $mtime &#x5B;1];
	$xfl = substr ( $data, 8, 1 );
	$os = substr ( $data, 8, 1 );
	$headerlen = 10;
	$extralen = 0;
	$extra = &quot;&quot;;
	if ($flags &amp; 4) {
		// 2-byte length prefixed EXTRA data in header 
		if ($len - $headerlen - 2 &lt; 8) {
			return false; // Invalid format 
		}
		$extralen = unpack ( &quot;v&quot;, substr ( $data, 8, 2 ) );
		$extralen = $extralen &#x5B;1];
		if ($len - $headerlen - 2 - $extralen &lt; 8) {
			return false; // Invalid format 
		}
		$extra = substr ( $data, 10, $extralen );
		$headerlen += 2 + $extralen;
	}
	
	$filenamelen = 0;
	$filename = &quot;&quot;;
	if ($flags &amp; 8) {
		// C-style string file NAME data in header 
		if ($len - $headerlen - 1 &lt; 8) {
			return false; // Invalid format 
		}
		$filenamelen = strpos ( substr ( $data, 8 + $extralen ), chr ( 0 ) );
		if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 &lt; 8) {
			return false; // Invalid format 
		}
		$filename = substr ( $data, $headerlen, $filenamelen );
		$headerlen += $filenamelen + 1;
	}
	
	$commentlen = 0;
	$comment = &quot;&quot;;
	if ($flags &amp; 16) {
		// C-style string COMMENT data in header 
		if ($len - $headerlen - 1 &lt; 8) {
			return false; // Invalid format 
		}
		$commentlen = strpos ( substr ( $data, 8 + $extralen + $filenamelen ), chr ( 0 ) );
		if ($commentlen === false || $len - $headerlen - $commentlen - 1 &lt; 8) {
			return false; // Invalid header format 
		}
		$comment = substr ( $data, $headerlen, $commentlen );
		$headerlen += $commentlen + 1;
	}
	
	$headercrc = &quot;&quot;;
	if ($flags &amp; 1) {
		// 2-bytes (lowest order) of CRC32 on header present 
		if ($len - $headerlen - 2 &lt; 8) {
			return false; // Invalid format 
		}
		$calccrc = crc32 ( substr ( $data, 0, $headerlen ) ) &amp; 0xffff;
		$headercrc = unpack ( &quot;v&quot;, substr ( $data, $headerlen, 2 ) );
		$headercrc = $headercrc &#x5B;1];
		if ($headercrc != $calccrc) {
			return false; // Bad header CRC 
		}
		$headerlen += 2;
	}
	
	// GZIP FOOTER - These be negative due to PHP's limitations 
	$datacrc = unpack ( &quot;V&quot;, substr ( $data, - 8, 4 ) );
	$datacrc = $datacrc &#x5B;1];
	$isize = unpack ( &quot;V&quot;, substr ( $data, - 4 ) );
	$isize = $isize &#x5B;1];
	
	// Perform the decompression: 
	$bodylen = $len - $headerlen - 8;
	if ($bodylen &lt; 1) {
		// This should never happen - IMPLEMENTATION BUG! 
		return null;
	}
	$body = substr ( $data, $headerlen, $bodylen );
	$data = &quot;&quot;;
	if ($bodylen &gt; 0) {
		switch ($method) {
			case 8 :
				// Currently the only supported compression method: 
				$data = gzinflate ( $body );
				break;
			default :
				// Unknown compression method 
				return false;
		}
	} else {
	
		// I'm not sure if zero-byte body content is allowed. 
	// Allow it for now...  Do nothing... 
	}
	
	// Verifiy decompressed size and CRC32: 
	// NOTE: This may fail with large data sizes depending on how 
	//       PHP's integer limitations affect strlen() since $isize 
	//       may be negative for large sizes. 
	if ($isize != strlen ( $data ) || crc32 ( $data ) != $datacrc) {
		// Bad format!  Length or CRC doesn't match! 
		return false;
	}
	return $data;
}

?&gt;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>在IIS中启用Gzip压缩</title>
		<link>https://www.mudbest.com/%e5%9c%a8iis%e4%b8%ad%e5%90%af%e7%94%a8http%e5%8e%8b%e7%bc%a9/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Fri, 29 Apr 2011 08:27:43 +0000</pubDate>
				<category><![CDATA[分享]]></category>
		<category><![CDATA[Gzip]]></category>
		<category><![CDATA[iis]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=632</guid>

					<description><![CDATA[IIS默认并不支持HTTP压缩，需要进行简单的配置 打开Internet信息服务(IIS)管理器，右击&#82 ... <a title="在IIS中启用Gzip压缩" class="read-more" href="https://www.mudbest.com/%e5%9c%a8iis%e4%b8%ad%e5%90%af%e7%94%a8http%e5%8e%8b%e7%bc%a9/" aria-label="阅读 在IIS中启用Gzip压缩">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>IIS默认并不支持HTTP压缩，需要进行简单的配置 </p>
<p>打开Internet信息服务(IIS)管理器，右击&#8221;网站&#8221;->&#8221;属性&#8221;，选择&#8221;服务&#8221;。在&#8221;HTTP压缩&#8221;框中选中&#8221;压缩应用程序文件&#8221;和&#8221;压缩静态文件&#8221;，按需要设置&#8221;临时目录&#8221;和&#8221;临时目录的最大限制&#8221;；<br />
<a href="http://www.mudbest.com/632.action/2-6" rel="attachment wp-att-633"><img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2011/04/21-370x429.jpg" alt="" title="2" width="370" height="429" class="alignnone size-medium wp-image-633" srcset="https://www.mudbest.com/wp-content/uploads/2011/04/21-370x429.jpg 370w, https://www.mudbest.com/wp-content/uploads/2011/04/21.jpg 544w" sizes="auto, (max-width: 370px) 100vw, 370px" /></a></p>
<p>在Internet信息服务(IIS)管理器，右击&#8221;Web服务扩展&#8221;->&#8221;增加一个新的Web服务扩展&#8230;&#8221;，在&#8221;新建Web服务扩展&#8221;框中输入扩展名&#8221;HTTP Compression&#8221;，添加&#8221;要求的文件&#8221;为C:\WINDOWS\system32\inetsrv\gzip.dll，其中Windows系统目录根据您的安装可能有所不同，选中&#8221;设置扩展状态为允许&#8221;； <span id="more-632"></span></p>
<p><a href="http://www.mudbest.com/632.action/3-5" rel="attachment wp-att-634"><img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2011/04/31-454x430.jpg" alt="" title="3" width="454" height="430" class="alignnone size-medium wp-image-634" srcset="https://www.mudbest.com/wp-content/uploads/2011/04/31-454x430.jpg 454w, https://www.mudbest.com/wp-content/uploads/2011/04/31.jpg 609w" sizes="auto, (max-width: 454px) 100vw, 454px" /></a></p>
<p>使用文本编辑器打开C:\Windows\System32\inetsrv\MetaBase.xml(建议先备份),<br />
找到Location =&#8221;/LM/W3SVC/Filters/Compression/gzip用于设置gzip压缩，<br />
找到Location =&#8221;/LM/W3SVC/Filters/Compression/deflate&#8221;用于设置deflate压缩.<br />
上面两个节点紧挨着.并且设置的属性相同. </p>
<p>如果需要压缩动态文件，则将HcDoDynamicCompression设置为&#8221;TRUE&#8221;，并在HcScriptFileExtensions中增加您要压缩的动态文件后缀名，如aspx；如果需要压缩静态文件，则将HcDoStaticCompression和HcDoOnDemandCompression设置为&#8221;TRUE&#8221;，并在HcFileExtensions中增加您需要压缩的静态文件后缀名，如xml、css等；HcDynamicCompressionLevel和HcOnDemandCompLevel表示需要的压缩率，数值在0-10, 默认为0.<br />
HcDynamicCompressionLevel属性说明:HcDynamicCompressionLevel Metabase Property<br />
HcOnDemandCompLevel 属性说明:HcOnDemandCompLevel Metabase Property </p>
<p>说明: 这两个属性值一般推荐设置为9, 具有最佳性价比.但是在我的window server 2003上, 压缩率无论如何设置, jQuery和jQuery UI两个文件(58k/188k)压缩后的大小一直相同.(20k/45k).  </p>
<p>一下是我的配置</p>
<p><a href="http://www.mudbest.com/632.action/1-8" rel="attachment wp-att-635"><img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2011/04/11-410x430.jpg" alt="" title="1" width="410" height="430" class="alignnone size-medium wp-image-635" srcset="https://www.mudbest.com/wp-content/uploads/2011/04/11-410x430.jpg 410w, https://www.mudbest.com/wp-content/uploads/2011/04/11.jpg 654w" sizes="auto, (max-width: 410px) 100vw, 410px" /></a></p>
<pre class="brush: xml; title: ; notranslate">
&lt;IIsCompressionScheme	Location =&quot;/LM/W3SVC/Filters/Compression/deflate&quot;
		HcCompressionDll=&quot;%windir%\system32\inetsrv\gzip.dll&quot;
		HcCreateFlags=&quot;0&quot;
		HcDoDynamicCompression=&quot;TRUE&quot;
		HcDoOnDemandCompression=&quot;TRUE&quot;
		HcDoStaticCompression=&quot;FALSE&quot;
		HcDynamicCompressionLevel=&quot;10&quot;
		HcFileExtensions=&quot;htm
			html
			txt&quot;
		HcOnDemandCompLevel=&quot;10&quot;
		HcPriority=&quot;1&quot;
		HcScriptFileExtensions=&quot;asp
php
xml
			dll
			exe&quot;
	&gt;
&lt;/IIsCompressionScheme&gt;
&lt;IIsCompressionScheme	Location =&quot;/LM/W3SVC/Filters/Compression/gzip&quot;
		HcCompressionDll=&quot;%windir%\system32\inetsrv\gzip.dll&quot;
		HcCreateFlags=&quot;1&quot;
		HcDoDynamicCompression=&quot;TRUE&quot;
		HcDoOnDemandCompression=&quot;TRUE&quot;
		HcDoStaticCompression=&quot;TRUE&quot;
		HcDynamicCompressionLevel=&quot;10&quot;
		HcFileExtensions=&quot;htm
			html
			txt&quot;
		HcOnDemandCompLevel=&quot;10&quot;
		HcPriority=&quot;1&quot;
		HcScriptFileExtensions=&quot;asp
php
xml
			dll
			exe&quot;
	&gt;
&lt;/IIsCompressionScheme&gt;
</pre>
<p>以下是测试结果</p>
<p><a href="http://www.mudbest.com/632.action/11-3" rel="attachment wp-att-641"><img loading="lazy" decoding="async" src="http://www.mudbest.com/wp-content/uploads/2011/04/111-502x430.jpg" alt="" title="11" width="502" height="430" class="alignnone size-medium wp-image-641" srcset="https://www.mudbest.com/wp-content/uploads/2011/04/111-502x430.jpg 502w, https://www.mudbest.com/wp-content/uploads/2011/04/111.jpg 691w" sizes="auto, (max-width: 502px) 100vw, 502px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
