<?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>嘻来嚷往国际版 &#187; 编程开发</title>
	<atom:link href="http://xirang.us/topics/it/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://xirang.us</link>
	<description>if you see something, say something.</description>
	<lastBuildDate>Fri, 11 Jun 2010 14:23:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>利用cPanel Cron jobs定时备份和优化网站程序以及数据</title>
		<link>http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs</link>
		<comments>http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs#comments</comments>
		<pubDate>Sun, 03 Jan 2010 13:06:47 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[Cron jobs]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[网站建设]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=1464</guid>
		<description><![CDATA[如今最优秀的主机面板cPanel已经越来越普及了，如果您有幸用上了采用cPanel面板的主机，那么其中的Cron jobs模块就是雪中送炭了。您不但可以使用Cron jobs结合Linux bash shell脚本更加细致地控制各种自动定时作业——备份数据库、优化数据库和备份网站程序，还可以永久性地省掉几个Wordpress插件，提高Wordpress的运行速度。]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p>
	当广大Wordpresser欢欣鼓舞地升级到2.9，享受着在线图片编辑器、回收站等一系列新功能的时候，却发现Wordpress的生理周期突然失调了&mdash;&mdash;以前她能够自动地定时为我们发布文章、清除缓存、备份数据库等等等等，而现在这一切都需要我们手工完成。经过在Wordpress官方论坛一番搜寻，发现原来这是Wordpress 2.9的大BUG&mdash;&mdash;定时模块失效&hellip;&hellip;
</p>
<p>
	又，最近在国内互联网&ldquo;扫黄打非&rdquo;的狂风暴雨下，个人网站的站长们被弄得一个个诚惶诚恐，一觉醒来说不定域名就&ldquo;被&rdquo;停止解析，服务器就&ldquo;被&rdquo;关停！所以，及时备份网站的程序和数据对于当下的中国站长们极为重要，然而Wordpress 2.9偏偏又在这当口来一个定时模块失效，这的确是雪上加霜！
</p>
<p style="text-align: center;">
	<a href="http://cpanel.net/" target="_blank"><img alt="CPanel" class="alignnone size-full wp-image-1465" height="71" src="http://xirang.us/media/2010/01/cpanel.jpg" style="" title="CPanel" width="761" /></a>
</p>
<p>
	不过，如今最优秀的主机面板cPanel已经越来越普及了，如果您有幸用上了采用cPanel面板的主机，那么其中的Cron jobs模块就是雪中送炭了。您不但可以使用Cron jobs结合Linux bash shell脚本更加细致地控制各种自动定时作业&mdash;&mdash;<a href="http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs#dbbackup">备份数据库</a>、<a href="http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs#dbopt">优化数据库</a>和<a href="http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs#progbackup">备份网站程序</a>，还可以永久性地省掉几个Wordpress插件，提高Wordpress的运行速度。
</p>
<h1>
	<a name="dbbackup"></a>定时自动备份MySQL数据库<br />
</h1>
<p>
	<img alt="Cron jobs" class="alignnone size-full wp-image-1466" height="187" src="http://xirang.us/media/2010/01/cron-jobs.jpg" style="cursor: default; float: right;" title="Cron jobs" width="508" />如右图所示，首先请在您的cPanel面板中的Advanced部分找到Cron jobs。点击进入，您就会看到Cron jobs的操作页面，不过先别着急，我们要首先编写备份网站数据库的Linux bash shell脚本。
</p>
<p>
	我们需要首先用mysqldump命令导出整个数据库至一个文本文件，然后用压缩工具将数据文件压缩打包，最后用mutt命令将数据库压缩包发送至您指定的电子邮件地址。
</p>
<p>
	现在我们开始，请用远程登录软件（如SecureCRT、Putty）或者FTP软件（如FileZilla、FireFTP）连接到您的主机，并创建一个存储备份脚本和临时文件的文件夹，比如我在我的主机根目录建立了一个backup目录。根据cPanel主机的文件夹格式，该目录的绝对路径应为/home/cPanel登录名/backup。
</p>
<p>
	下面以/home/xirangus/backup目录为例。请打开任意一个文本编辑软件，录入如下内容。[XXX]处请更换为您的真实数据（去掉[和]）。<span id="more-1464"></span>
</p>
<div class="entry">
<div class="entry">
<style>.codecolorer,.codecolorer-container table td.line-numbers{padding:5px}.codecolorer,.codecolorer-container{text-align:left}code.codecolorer{padding:2px}.codecolorer-container{margin-bottom:10px;border:1px solid #9f9f9f}.codecolorer-container *,.codecolorer-container,.codecolorer *,.codecolorer{font:13px/1.4em Monaco,Lucida Console,monospace}.codecolorer-container table,.codecolorer-container table td,.codecolorer-noborder table td.line-numbers,.codecolorer-noborder{border:0}.codecolorer-container table td{margin:0;padding:0}.codecolorer-container table td.line-numbers{text-align:right;background:#eee;color:#888;border-right:1px solid #9f9f9f}.codecolorer-container table td.line-numbers div{width:23px}.dawn .codecolorer,.dawn{background:#f9f9f9}.dawn .codecolorer,.dawn,code.dawn .sy0,code.dawn .br0,.dawn .codecolorer .sy0,.dawn .codecolorer .br0{color:#080808}code.dawn .coMULTI,code.dawn .co4,code.dawn .co3,code.dawn .co2,code.dawn .co1,code.dawn .co0,.dawn .codecolorer .coMULTI,.dawn .codecolorer .co4,.dawn .codecolorer .co3,.dawn .codecolorer .co2,.dawn .codecolorer .co1,.dawn .codecolorer .co0{color:#5a525f;font-style:italic}code.dawn .re3,code.dawn .nu0,.dawn .codecolorer .re3,.dawn .codecolorer .nu0,.dawn .xml .re0{color:#811f24}code.dawn .es1,code.dawn .es0,code.dawn .st_h,code.dawn .st0,.dawn .codecolorer .es1,.dawn .codecolorer .es0,.dawn .codecolorer .st_h,.dawn .codecolorer .st0{color:#0b6125}code.dawn .me2,code.dawn .me1,.dawn .codecolorer .me2,.dawn .codecolorer .me1{color:#bf4f24}code.dawn .sy1,code.dawn .kw2,code.dawn .kw1,.dawn .codecolorer .sy1,.dawn .codecolorer .kw2,.dawn .codecolorer .kw1{color:#794938}code.dawn .re2,code.dawn .kw5,code.dawn .kw4,code.dawn .kw3,.dawn .codecolorer .re2,.dawn .codecolorer .kw5,.dawn .codecolorer .kw4,.dawn .codecolorer .kw3,.dawn .xml .re1{color:#a71d5d}code.dawn .re1,code.dawn .re0,.dawn .codecolorer .re1,.dawn .codecolorer .re0{color:#234a97}</style>
<div class="codecolorer-container bash dawn" style="overflow: auto; white-space: nowrap; width: 860px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>
								1<br />
								2<br />
								3<br />
								4<br />
								5<br />
								6
							</div>
</td>
<td>
<div class="bash codecolorer" style="white-space: nowrap;">
								<span class="kw3">cd</span> <span class="sy0">/</span>home<span class="sy0">/</span>xirangus<span class="sy0">/</span>backup <span class="co0">#切换到工作目录</span><br />
								<span class="re2">stamp</span>=$<span class="br0">(</span><span class="kw2">date</span> + <span class="sy0">%</span>y<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="br0">)</span> <span class="co0">#获取当前日期</span><br />
								mysqldump -u<span class="br0">[</span>数据库用户名<span class="br0">]</span> -p<span class="br0">[</span>数据库密码<span class="br0">]</span> <span class="br0">[</span>数据库名<span class="br0">]</span> <span class="sy0">&gt;</span> &nbsp;db_backup_<span class="re1">$</span><span class="re2">stamp</span>.sql <span class="co0">#导出数据库</span><br />
								<span class="kw2">bzip2</span> <span class="re5">-z</span> <span class="re5">-9</span> <span class="re5">-f</span> db_backup_<span class="re2">$stamp</span>.sql <span class="co0">#压缩数据库</span><br />
								mutt <span class="br0">[</span>电子邮件地址<span class="br0">]</span> <span class="re5">-a</span>&nbsp;db_backup_<span class="re1">$</span><span class="re2">stamp</span>.sql.bz2 <span class="re5">-s</span> <span class="st0">&quot;Database Backup&quot;</span> <span class="co0">#邮件发送</span><br />
								<span class="kw2">rm</span> db_backup_<span class="re1">$suffix</span>.sql.bz2 <span class="co0">#移除临时文件</span>
							</div>
</td>
</tr>
</tbody>
</table></div>
<p>
			其中第4行采用了bzip2来压缩数据，如果您的主机不支持bzip2，请更换为使用tar或zip等命令来压缩数据，具体情况请咨询您的主机商。
		</p>
<p>
			脚本录入完毕后，请将其保存，比如我将其命名为dbbackup.sh。然后上传到刚刚建立的/home/xirangus/backup目录下，并<strong>更改该脚本文件的权限为755</strong>。
		</p>
<p>
			大功快要告成，现在请点击cPanel中的Cron jobs图标，选择Standard进入标准模式。将/home/xirangus/backup/dbbackup.sh填入Command to run中，并选择定时运行方式，如下图。
		</p>
<p style="text-align: center;">
			<img alt="Add Cron Jobs/添加定时工作项目" class="alignnone size-full wp-image-1467" height="502" src="http://xirang.us/media/2010/01/cron-jobs-add.png" title="Add Cron Jobs/添加定时工作项目" width="758" />
		</p>
<p>
			这里的时间是以服务器的时区为准，所以您需要自己换算一下。嘻来嚷往所在的<a href="http://xirang.us/r.php?t=a&amp;id=justhost" target="_blank">Just Host</a>的数据中心位于美国中部时区，比中国标准时间晚14个小时，所以按照上图设置，每天中国标准时间晚上8点，嘻来嚷往的数据库备份邮件就会自动被发送到我的邮箱里。
		</p>
<h1>
			<a name="dbopt"></a>定时自动优化MySQL数据库<br />
		</h1>
<p>
			频繁地对数据库进行各种操作，会使数据库产生一些错误和冗余数据而导致性能下降，因此及时修复和优化数据库也是非常必要的。我们可以采用mysqlcheck命令对MySQL数据库进行修复和优化。脚本文件如下。
		</p>
<div class="entry">
<div class="codecolorer-container bash dawn" style="overflow: auto; white-space: nowrap; width: 860px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>
									1<br />
									2
								</div>
</td>
<td>
<div class="bash codecolorer" style="white-space: nowrap;">
									mysqlcheck -u<span class="br0">[</span>数据库用户名<span class="br0">]</span> -p<span class="br0">[</span>数据库密码<span class="br0">]</span> <span class="re5">&#8211;auto-repair</span> <span class="re5">&#8211;database</span> <span class="br0">[</span>数据库名<span class="br0">]</span> <span class="co0">#检查并自动修复数据库</span><br />
									mysqlcheck -u<span class="br0">[</span>数据库用户名<span class="br0">]</span> -p<span class="br0">[</span>数据库密码<span class="br0">]</span> <span class="re5">-o</span> <span class="re5">&#8211;database</span> <span class="br0">[</span>数据库名<span class="br0">]</span> <span class="co0">#优化数据库</span>
								</div>
</td>
</tr>
</tbody>
</table></div>
<p>
				如何让Cron jobs自动运行脚本就不再赘述了。
			</p>
</p></div>
<h1>
			<a name="progbackup"></a>定时自动备份网站程序<br />
		</h1>
<p>
			有了前面数据库的列子，备份程序文件就简单多了，稍稍修改一下脚本文件就行了。还是以Wordpress为例吧，一般我们修改得最多的就是主题文件，所以我们就让Cron jobs定时备份Wordpress的themes文件夹吧。直接给出脚本文件。
		</p>
<div class="entry">
<div class="codecolorer-container bash dawn" style="overflow: auto; white-space: nowrap; width: 860px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>
									1<br />
									2<br />
									3<br />
									4<br />
									5<br />
									6
								</div>
</td>
<td>
<div class="bash codecolorer" style="white-space: nowrap;">
									<span class="kw3">cd</span> <span class="sy0">/</span>home<span class="sy0">/</span>xirangus<span class="sy0">/</span>backup <span class="co0">#切换工作目录</span><br />
									<span class="re2">stamp</span>=$<span class="br0">(</span><span class="kw2">date</span> + <span class="sy0">%</span>y<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="br0">)</span> <span class="co0">#获取当前日期</span><br />
									<span class="kw2">tar</span> <span class="re5">-cvf</span> theme_<span class="re1">$stamp</span>.tar <span class="sy0">/</span>home<span class="sy0">/</span>xirangus<span class="sy0">/</span>public_html<span class="sy0">/</span>wp-content<span class="sy0">/</span>themes <span class="co0">#打包主题目录</span><br />
									<span class="kw2">bzip2</span> <span class="re5">-z</span> <span class="re5">-9</span> <span class="re5">-f</span> theme_<span class="re1">$stamp</span>.tar <span class="co0">#压缩</span><br />
									mutt [电子邮件地址] <span class="re5">-a</span> theme_<span class="re1">$stamp</span>.tar.bz2 <span class="re5">-s</span> <span class="st0">&quot;Themes Backup&quot;</span> <span class="co0">#邮件发送</span><br />
									<span class="kw2">rm</span> theme_<span class="re1">$stamp</span>.tar.bz2 <span class="co0">#移除临时文件</span>
								</div>
</td>
</tr>
</tbody>
</table></div>
</p></div>
</p></div>
</div>
<p>
	虽然tar命令可以使用-j参数进行bzip2的打包+压缩，但是不能指定压缩级别，所以我还是采用了tar先打包，接着使用bzip2最高级别压缩的方式。
</p>
<p>
	就介绍这么多吧，如果您熟悉Linux，那么您还可以尽情发挥，让Cron jobs完成更多的自动定时作业，使网站的运行更加高效和有保障。
</p>
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：利用cPanel Cron jobs定时备份和优化网站程序以及数据<br />发表日期：2010年01月03日<br />原文链接：<a href="http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs" >http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=1464&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2010/01/backup-and-optimize-website-by-cpanel-cron-jobs/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>WP Super Cache之诡异GZip压缩包下载BUG</title>
		<link>http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache</link>
		<comments>http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache#comments</comments>
		<pubDate>Mon, 21 Dec 2009 09:00:55 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[网站建设]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=1422</guid>
		<description><![CDATA[WP Super Cache 0.9.8导致浏览器无法打开基于Wordpress架设的网站，而是提示访问者下载GZip压缩包，该压缩包解压后，为网站首页的html文档。并且任何内核的浏览器都可能出现此情况。]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p>请各个基于Wordpress架设并且开启了WP Super Cache插件进行提速的网站的站长们注意，在嘻来嚷往热心读者的帮助下，我们发现了WP Super Cache 0.9.8版本所引入的一个十分诡异和难以察觉的BUG！</p>
<p style="text-align: center; "><a href="http://xirang.us/media/2009/12/bug-fest.jpg"><img alt="bug-fest" class="alignnone size-full wp-image-1424" height="548" src="http://xirang.us/media/2009/12/bug-fest.jpg" title="bug-fest" width="600" /></a></p>
<h2>前提条件</h2>
<ol>
<li>WP Super Cache Status: 开启</li>
<li>Super Cache Compression: 开启</li>
<li>Expiry Time &amp; Garbage Collection: 较长，比如嘻来嚷往设定为86400秒（一天）</li>
</ol>
<p>如果您Wordpress网站的WP Super Cache设置符合上述三个条件，请向贵站的读者咨询他们在访问网站时是否出现过以下（比较罕见，就算您自己刷新网站100次可能也不会出现，所以做好求助于网站的大量访问者）</p>
<h2>现象</h2>
<p>浏览器无法打开网站，而是提示访问者<strong>下载GZip压缩包</strong>，该压缩包解压后，为网站首页的html文档。并且任何内核的浏览器都可能出现此情况。<span id="more-1422"></span></p>
<p>如果收到了上诉现象的报告，那么恭喜您的网站中招了！尽管进入WP Super Cache设置页面，<strong>清除缓存</strong>后GZip压缩包下载现象立即消失，但是<strong>不久后又会出现<span class="Apple-style-span" style="font-weight: normal; ">；并且一旦出现过一次这样的情况，就算关闭WP Super Cache的Super Cache Compression选项试图亡羊补牢却仍然无济于事。</span></strong></p>
<p>半个月前，本站访问者开始报告这个现象，当时凭直觉断定肯定是WP Super Cache的问题，但问题在哪里并不清楚，只好彻底卸载WP Super Cache后全新安装，并关闭Super Cache Compression选项，这样似乎持续了一个星期问题未再出现。</p>
<p>可是后来再次出现很多遇到了GZip压缩包下载的现象报告，崩溃之余开始搜索，无果！只好去WP Super Cache的支持论坛一页页翻看，终于发现一位外国老兄也也遇到了<a href="http://wordpress.org/support/topic/334359" target="_blank">这个情况</a>。但是插件作者坚称这不是WP Super Cache的BUG，其原话如下：</p>
<blockquote>
<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 14px; line-height: 22px; ">Very very occasionally, the front page becomes a gzip file that downloads. It happened here once and I examined the cache file. There was nothing wrong with it. It was perfect. I suspect Apache and mod_rewrite got confused somehow but clearing the cache fixed it. The file generated after was exactly the same size as the old one, so no chance it got &ldquo;double gzipped&rdquo;.</span></p>
</blockquote>
<h2>解决方案</h2>
<p>我就纳闷了，服务器配置未更改过、Wordpress主程序也未升级过，外部环境都没改变，可是WP Super Cache升级到0.9.8就出现这个问题，难道不是它的BUG？这BUG真够诡异，连作者自己都无法找到问题的根源，只能坚称这是Apache的问题，不过他还是给出了一个<strong>指标不治本</strong>的解决方案。</p>
<p>打开/wp-contents/wp-cache-config.php文件，在其中加入下面这行代码：</p>
<p>[cc lang=&quot;PHP&quot;]$wp_super_cache_advanced_debug = 1;[/cc]</p>
<p>接着进入WP Super Cache设置页面，将看到以下<strong>Advanced</strong>部分</p>
<p style="text-align: center; "><a href="http://xirang.us/media/2009/12/wpsc-advanced.jpg"><img alt="wpsc-advanced" class="alignnone size-full wp-image-1423" height="305" src="http://xirang.us/media/2009/12/wpsc-advanced.jpg" title="wpsc-advanced" width="606" /></a></p>
<p>开启之后，WP Super Cache将每隔五分钟检查一次网站首页，并在首页数据中搜索指定的字符串，如果字符串不存在，WP Super Cache就认为网站首页缓存出错，于是会自动清除并重建缓存。</p>
<p>WP Super Cache作者还说，如果这样也不能解决问题，那就只有把Expiry Time &amp; Garbage Collection设为5分钟或者更短，以让WP Super Cache频繁清除缓存。我想如果非这样不可，还不如卸载了WP Super Cache，如此频繁的重建缓存，只会降低Wordpress的速度&hellip;&hellip;期待WP Super Cache作者找到问题根源在下个版本中除掉这个BUG！</p>
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：WP Super Cache之诡异GZip压缩包下载BUG<br />发表日期：2009年12月21日<br />原文链接：<a href="http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache" >http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=1422&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2009/12/peculiar-gzip-download-bug-of-wp-super-cache/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SkyDrive 外链自动获取插件 WP-Skydrive-Outlink 完善版</title>
		<link>http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod</link>
		<comments>http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod#comments</comments>
		<pubDate>Fri, 07 Aug 2009 12:18:49 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Skydrive]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[外链]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=859</guid>
		<description><![CDATA[天下可以有免费的午餐，但是真的没有又免费又丰盛的午餐……为了防止像本站一样，长期、稳定地外链 SkyDrive 文件，微软可是做足了功夫，某个文件的外链地址随时都在改变。唯一不变的就是下载页面，为的就是让你去看广告。搜了半天，在《Skydrive外链(wp-skydrive-outlink)插件》找到了高人 Flarefox 编写的，通过分析那个不变的文件下载页面代码找出此时此刻该文件的外链地址的 WordPress 插件。Tim站在Flarefox 的肩膀上对插件做了一点小小的修改，让它工作得更棒！]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p><span style="color: #ff6600;">站长提示：如果您点击本文中的链接后出现了广告画面，麻烦您等待5秒后点击右上角的</span><strong>SKIP AD</strong><span style="color: #ff6600;">按钮跳过广告继续查看链接内容。对您造成的不便我们深感歉意，但是这一点微薄的广告收入可以维持本站的正常运作，全站作者由衷地感谢您的谅解与支持。</span><br />
<hr size="1" color="#bd1016"/></p>
<p>话说为了为本站的视频文件找个家，<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>可是费尽心思，国内外的外链文件存储网站几乎全部注册试用了一遍，到最后还是锁定在了垂手可得的微软 25G 不限流量外链空间 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 。一来是微软的服务器那是相当的稳定，二来是在我有生之年估计微软也不会倒闭，那就把视频文件存在 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 吧。</p>
<p>不过，天下可以有免费的午餐，但是真的没有又免费又丰盛的午餐&hellip;&hellip;为了防止像本站一样，长期、稳定地外链 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 文件，微软可是做足了功夫，某个文件的外链地址随时都在改变。唯一不变的就是下载页面，为的就是让你去看广告。搜了半天，在《<a href="http://www.mathelite.cn/archives/wordpress-skydrive-outlink-plugin.html" target="_blank" title="Skydrive外链(wp-skydrive-outlink)插件">Skydrive外链(wp-skydrive-outlink)插件</a>》这里找到了高人编写的，通过分析那个不变的文件下载页面代码找出此时此刻该文件的外链地址的 WordPress 插件。</p>
<p>但是 <a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a> 在使用的时候发现了不尽人意的地方。原插件是通过搜索页面代码的如下内容：</p>
<div class="codecolorer-container html4strict dawn" style="overflow: auto; white-space: nowrap; width: 865px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>1</div>
</td>
<td>
<div class="html4strict codecolorer" style="white-space: nowrap;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/a.html"><span class="kw2">a</span></a> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;http&amp;#58;&amp;#47;&amp;#47;zmmbva.bay.livefilestore.com&amp;#47y1pIqCe7pRjb5SoIojzYoEoZwIWrS4ydWQbUfVTc9AzsqDWEPyeTDpBTN2zresvpobyBvHUv1ApuBAcoojvXGkYYg&amp;#47;Breath&amp;#37;20Under&amp;#37;20Water&amp;#37;20HQ.mp4&amp;#63;download&quot;</span> <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;Download&quot;</span>&gt;</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<p>中的 title=&rdquo;Download&rdquo; 来截取外链地址。但是 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 的页面语言会根据浏览器 Cookie 和浏览者 IP 地址而做出自动选择。如果浏览者的 Windows Live 语言设置为非英文，或者是浏览者从没登录过 Windows Live ，那么他所得到的这个下载页面的 title=&rdquo;Download&rdquo; 很可能就变成 title=&rdquo;下载&rdquo;、title=&rdquo;t&eacute;l&eacute;charger&rdquo;、title=&rdquo;ダウンロードする&rdquo; 等等等等，那么这个插件也就失效了。</p>
<p>	所以，<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>又瞧了瞧 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 文件下载页面的源码，发现在靠近底部，有一段 javascript 代码：</p>
<div class="codecolorer-container javascript dawn" style="overflow: auto; white-space: nowrap; width: 865px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>1<br />
						2<br />
						3<br />
						4<br />
						5<br />
						6<br />
						7<br />
						8<br />
						9<br />
						10<br />
						11<br />
						12<br />
						13<br />
						14<br />
						15<br />
						16<br />
						17<br />
						18<br />
						19<br />
						20</div>
</td>
<td>
<div class="javascript codecolorer" style="white-space: nowrap;"><span class="kw2">var</span> $SelfPage <span class="sy0">=</span> <span class="kw2">new</span> <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><br />
						<span class="br0">{</span><br />
						&nbsp; &nbsp; var_download <span class="sy0">=</span> <span class="st0">&#39;http<span class="es0">\x</span>3a<span class="es0">\x</span>2f<span class="es0">\x</span>2fzmmbva.bay.livefilestore.com<span class="es0">\x</span>2fy1pIqCe7pRjb5SoIojzYoEoZwIWrS4ydWQbUfVTc9AzsqDWEPyeTDpBTN2zresvpobyBvHUv1ApuBAcoojvXGkYYg<span class="es0">\x</span>2fBreath<span class="es0">\x</span>2520Under<span class="es0">\x</span>2520Water<span class="es0">\x</span>2520HQ.mp4<span class="es0">\x</span>3fdownload&#39;</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; var_demote <span class="sy0">=</span> <span class="st0">&#39;http<span class="es0">\x</span>3a<span class="es0">\x</span>2f<span class="es0">\x</span>2fzmmbva.bay.livefilestore.com<span class="es0">\x</span>2fy1pIqCe7pRjb5SoIojzYoEoZwIWrS4ydWQbUfVTc9AzsqDWEPyeTDpBTN2zresvpobyBvHUv1ApuBAcoojvXGkYYg<span class="es0">\x</span>2fBreath<span class="es0">\x</span>2520Under<span class="es0">\x</span>2520Water<span class="es0">\x</span>2520HQ.mp4<span class="es0">\x</span>3fdownload&#39;</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; var_dirty <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span></p>
<p>						&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">MarkDirty</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> _dirty <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span> <span class="br0">}</span><br />
						&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">Download</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><br />
						&nbsp; &nbsp; <span class="br0">{</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">(</span>_dirty<span class="br0">)</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">{</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _dirty <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span class="me1">location</span> <span class="sy0">=</span> _demote<span class="sy0">;</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">}</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">{</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span class="me1">location</span> <span class="sy0">=</span> _download<span class="sy0">;</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">}</span><br />
						&nbsp; &nbsp; <span class="br0">}</span><br />
						<span class="br0">}</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<p>这个地方就是生成链接地址的函数，而且这个函数的内容不随页面语言和访问者 IP 地址的改变而改变。接着<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>就开始修改代码。本人对 PHP 一窍不通，还好 PHP 的字符串操作和 C++ 蛮像的，这里也只用修改一下搜寻字符串的地方，原作者其它那些代码对我来说是一本天书。修改后的地方是这样的：</p>
<div class="codecolorer-container php dawn" style="overflow: auto; white-space: nowrap; width: 865px;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="line-numbers">
<div>1<br />
						2<br />
						3<br />
						4<br />
						5<br />
						6<br />
						7<br />
						8<br />
						9<br />
						10<br />
						11<br />
						12<br />
						13<br />
						14<br />
						15<br />
						16<br />
						17<br />
						18<br />
						19<br />
						20<br />
						21<br />
						22<br />
						23<br />
						24</div>
</td>
<td>
<div class="php codecolorer" style="white-space: nowrap;"><span class="kw2">function</span> skydrive_get_outlink<span class="br0">(</span><span class="re0">$url</span><span class="br0">)</span><br />
						<span class="br0">{</span><br />
						&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">(</span> IsAbsoluteUrl<span class="br0">(</span><span class="re0">$url</span><span class="br0">)</span> <span class="sy0">===</span> <span class="kw4">false</span> <span class="br0">)</span> <span class="br0">{</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$url</span> <span class="sy0">=</span> <span class="re0">$sdoldefaulturl</span> <span class="sy0">.</span> <span class="re0">$url</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="br0">}</span><br />
						&nbsp; &nbsp; <span class="re0">$body</span> <span class="sy0">=</span> ffox_get_http_body<span class="br0">(</span><span class="re0">$url</span><span class="br0">)</span><span class="sy0">;</span></p>
<p>						&nbsp; &nbsp; <span class="re0">$pos</span> <span class="sy0">=</span> <a href="http://www.php.net/stripos"><span class="kw3">stripos</span></a><span class="br0">(</span><span class="re0">$body</span><span class="sy0">,</span> <span class="st_h">&#39;var _demote&#39;</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$body</span> <span class="sy0">=</span> <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">(</span><span class="re0">$body</span><span class="sy0">,</span> 0<span class="sy0">,</span> <span class="re0">$pos</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$startstr</span> <span class="sy0">=</span> <span class="st_h">&#39;var _download = \&#39;&#39;</span><span class="sy0">;</span><span class="co1">//Tim modified in version 0.3: to locate the start position of the outlink</span><br />
						&nbsp; &nbsp; <span class="re0">$endstr</span> <span class="sy0">=</span> <span class="st_h">&#39;\\x3f&#39;</span><span class="sy0">;</span><span class="co1">//Tim modified in version 0.3: to locate the end position of the outlink</span><br />
						&nbsp; &nbsp; <span class="re0">$start</span> <span class="sy0">=</span> <a href="http://www.php.net/strripos"><span class="kw3">strripos</span></a><span class="br0">(</span><span class="re0">$body</span><span class="sy0">,</span> <span class="re0">$startstr</span><span class="br0">)</span> <span class="sy0">+</span> <a href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">(</span><span class="re0">$startstr</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$end</span> <span class="sy0">=</span> <a href="http://www.php.net/strripos"><span class="kw3">strripos</span></a><span class="br0">(</span><span class="re0">$body</span><span class="sy0">,</span> <span class="re0">$endstr</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$outlink</span> <span class="sy0">=</span> <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">(</span><span class="re0">$body</span><span class="sy0">,</span><span class="re0">$start</span><span class="sy0">,</span> <span class="re0">$end</span><span class="sy0">-</span><span class="re0">$start</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$outlink</span> <span class="sy0">=</span> <a href="http://www.php.net/str_replace"><span class="kw3">str_replace</span></a><span class="br0">(</span><span class="st_h">&#39;\\x3a&#39;</span><span class="sy0">,</span> <span class="st_h">&#39;:&#39;</span><span class="sy0">,</span> <span class="re0">$outlink</span><span class="br0">)</span><span class="sy0">;</span><span class="co1">//Tim added in version 0.3: to replace \x3a to :</span><br />
						&nbsp; &nbsp; <span class="re0">$outlink</span> <span class="sy0">=</span> <a href="http://www.php.net/str_replace"><span class="kw3">str_replace</span></a><span class="br0">(</span><span class="st_h">&#39;\\x2f&#39;</span><span class="sy0">,</span> <span class="st_h">&#39;/&#39;</span><span class="sy0">,</span> <span class="re0">$outlink</span><span class="br0">)</span><span class="sy0">;</span><span class="co1">//Tim added in version 0.3 to replace \x2f to /</span><br />
						&nbsp; &nbsp; <span class="re0">$outlink</span> <span class="sy0">=</span> <a href="http://www.php.net/str_replace"><span class="kw3">str_replace</span></a><span class="br0">(</span><span class="st_h">&#39;\\x25&#39;</span><span class="sy0">,</span> <span class="st_h">&#39;%&#39;</span><span class="sy0">,</span> <span class="re0">$outlink</span><span class="br0">)</span><span class="sy0">;</span><span class="co1">//Tim added in version 0.3 to replace \x25 to %</span><br />
						&nbsp; &nbsp; <a href="http://www.php.net/preg_match_all"><span class="kw3">preg_match_all</span></a><span class="br0">(</span><span class="st0">&quot;/\&amp;amp;\#([0-9]+)\;/&quot;</span><span class="sy0">,</span> <span class="re0">$outlink</span><span class="sy0">,</span> <span class="re0">$acs</span><span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="re0">$acs</span> <span class="sy0">=</span> <span class="re0">$acs</span><span class="br0">[</span>1<span class="br0">]</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">(</span><span class="re0">$acs</span> <span class="kw1">as</span> <span class="re0">$ac</span><span class="br0">)</span> <span class="br0">{</span><br />
						&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$outlink</span> <span class="sy0">=</span> <a href="http://www.php.net/preg_replace"><span class="kw3">preg_replace</span></a><span class="br0">(</span><span class="st0">&quot;/\&amp;amp;\#([0-9]+)\;/&quot;</span><span class="sy0">,</span> <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">(</span><span class="re0">$ac</span><span class="br0">)</span><span class="sy0">,</span> <span class="re0">$outlink</span><span class="sy0">,</span>1<span class="br0">)</span><span class="sy0">;</span><br />
						&nbsp; &nbsp; <span class="br0">}</span><br />
						&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$outlink</span><span class="sy0">;</span><br />
						<span class="br0">}</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<p>这么一修改，插件运作地就很良好了，<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>用Firefox、Chrome、Safari、Opera、IE都做了测试，效果非常不错！《<a href="http://xirang.us/2009/2009/08/hq-collection-of-marie-digby-from-youtube" rel="bookmark" title="Permanent Link to This Article">Mair&eacute; Digby YouTube 官方站高清 MV 合集</a>》中的所有视频都是采用 <a class="toptip extlink" href="http://adf.ly/Omf" target="_blank">SkyDrive</a> 存储，此插件获得外链地址的，您可以点过去瞧瞧效果。怎么样，这个插件的确不错吧，那么请</p>
<h1 style="text-align: center;"><span style="color: rgb(255, 0, 0);"><a class="toptip extlink" href="http://adf.ly/13mE" target="_blank" title="WP-Skydrive-Outlink Tim Mod">点击下载（2010.1.1更新，请将下载的文件的后缀名改为.zip）</a></span></h1>
<p>在这里<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>要感谢<a href="http://mathelite.cn/" title="Flarefox"><strong>Flarefox </strong></a>，他的所做工作是开创性的，我只是站在<a href="http://mathelite.cn/" title="Flarefox"><strong>Flarefox </strong></a>的肩膀上对插件做了一点小小的修改，让它工作得更棒！请<strong><a href="http://mathelite.cn/" title="Flarefox"><strong>Flarefox</strong></a></strong>看到此修改版、并且觉得<a href="http://xirang.us/2009/author/tim" target="_blank" title="Tim在嘻来嚷往上的所有文章">Tim</a>修改的还不错后，将我的版本合并到你的官方版本中，以让更多人更好的享受这顿&ldquo;又免费又丰盛的午餐&rdquo;！</p>
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：SkyDrive 外链自动获取插件 WP-Skydrive-Outlink 完善版<br />发表日期：2009年08月07日<br />原文链接：<a href="http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod" >http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=859&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2009/08/wordpress-skydrive-outlink-tim-mod/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>基于维基百科的WordPress全站中文繁简转换插件</title>
		<link>http://xirang.us/2009/07/wordpress-chinese-conversion-plugin</link>
		<comments>http://xirang.us/2009/07/wordpress-chinese-conversion-plugin#comments</comments>
		<pubDate>Mon, 27 Jul 2009 11:27:33 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[简繁转换]]></category>
		<category><![CDATA[维基百科]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=837</guid>
		<description><![CDATA[笔者曾在文章《利用中文维基百科实现基于表达习惯的高质量中文简繁转换》中介绍过巧妙使用中文维基百科的用户页面实现免费高质量中文简繁转换的方法。然而今天笔者发现，WordPress世界里面有位超级高人已经把这项功能实现为WordPress的插件了！安装了这个插件后将其添加到您WordPress网站的侧边栏里，将会为你的网站提供实时的、服务器端的、基于MediaWiki引擎的高质量全站中文简繁转换。]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2009/07/wordpress-chinese-conversion-plugin#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p><span style="color: #ff6600;">站长提示：如果您点击本文中的链接后出现了广告画面，麻烦您等待5秒后点击右上角的</span><strong>SKIP AD</strong><span style="color: #ff6600;">按钮跳过广告继续查看链接内容。对您造成的不便我们深感歉意，但是这一点微薄的广告收入可以维持本站的正常运作，全站作者由衷地感谢您的谅解与支持。</span><br />
<hr size="1" color="#bd1016"/></p>
<p>毫无疑问，<a title="大家一起来努力，早日赶超英文维基百科" href="http://adf.ly/M3y" target="_blank">维基百科</a>和<a title="WordPress.org" href="http://adf.ly/M8F" target="_blank">WordPress</a>都是它们各自领域的佼佼者。当它们的威力组合在一起的时候，那只能用圣斗士小宇宙爆发来形容了。</p>
<p><a title="Tim在嘻来嚷往上的所有文章" href="http://xirang.us/author/tim" target="_self">笔者</a>曾在文章<a title="固定链接：利用中文维基百科实现基于表达习惯的高质量中文简繁转换" rel="bookmark" href="http://xirang.us/2009/07/high-quality-conversion-between-simplified-and-traditional-chinese">《利用中文维基百科实现基于表达习惯的高质量中文简繁转换》</a>中介绍过巧妙使用<a title="大家一起来努力，早日赶超英文维基百科" href="http://adf.ly/M3y" target="_blank">中文维基百科</a>的用户页面实现免费高质量中文简繁转换的方法。</p>
<p>然而今天<a title="Tim在嘻来嚷往上的所有文章" href="http://xirang.us/author/tim" target="_self">笔者</a>发现，WordPress世界里面有位超级高人已经把这项功能实现为WordPress的插件了！安装了这个插件后将其添加到您WordPress网站的侧边栏里，将会为你的网站提供实时的、服务器端的、基于<a title="MediaWiki" href="http://adf.ly/M8C" target="_blank">MediaWiki</a>引擎的高质量全站中文简繁转换。</p>
<p style="text-align: center;"><a title="Wikipedia" href="http://adf.ly/M3y" target="_blank"><img class="alignnone" title="Wikipedia Logo" src="http://farm3.static.flickr.com/2591/3761724402_e2aa02c323_m.jpg" alt="Wikipedia" width="192" height="192" /></a><img class="alignnone" title="plus" src="http://farm3.static.flickr.com/2496/3761799326_ab4171ecc3_m.jpg" alt="" width="130" height="130" /><a title="WordPress" href="http://adf.ly/M8F" target="_blank"><img class="alignnone" title="WordPress Logo" src="http://farm4.static.flickr.com/3499/3760919565_91b31d5882_m.jpg" alt="WordPress" width="192" height="192" /></a></p>
<p>这真是个价值连城的东西，<a title="Tim在嘻来嚷往上的所有文章" href="http://xirang.us/author/tim" target="_self">笔者</a>赶紧把它装在了我的WordPress中。现在，您可以点击<a title="嘻来嚷往" href="http://xirang.us" target="_self">嘻来嚷往</a>站侧边栏中第二个名为“全站中文简繁转换”部件中的转换链接，查看这个插件的转换效果。</p>
<p>如果您也使用WordPress架设自己的网站，那么赶紧下载吧。您也可以先看看后面的插件介绍，在决定您是否下载使用它）。<span id="more-837"></span></p>
<ul>
<li>插件作者BLOG：<a title="小野大神 Blog" href="http://adf.ly/M8V" target="_blank">小野大神 Blog</a></li>
<li>插件下载页面：<a title="WP Chinese Conversion" href="http://adf.ly/M8I" target="_blank">WP Chinese Conversion</a></li>
</ul>
<p>如果您觉得这个插件很棒，记住在<a title="WordPress.org" href="http://adf.ly/M8F" target="_blank">WordPress.org</a>给它打一个高分！</p>
<p>支持WordPress、支持国人劳动成果！<br />
<?php generate_copyright('sa'); ?></p>
<h3>以下引用并修改自<a title="WordPress.org" href="http://adf.ly/M8F" target="_blank">WordPress.org</a>上的<a title="WP Chinese Conversion" href="http://adf.ly/M8I" target="_blank">WP Chinese Conversion</a>插件页面</h3>
<hr />这个插件为中文Blogger设计, 提供完整的基于服务器端的中文繁简转换解决方案. 相比用Javascript进行客户端繁简转换, 本插件提供的转换功能更为专业和可靠, 支持六种中文语言: 简体中文(zh-hans), 繁体中文(zh-hant) , 台湾正体(zh-tw), 港澳繁体(zh-hk), 马新简体(zh-sg)和大陆简体(zh-cn); 并且提供更多其它特性. 插件使用的繁简转换表和核心转换技术均来源于<a title="MediaWiki" href="http://adf.ly/M8C" target="_blank">MediaWiki</a>, 最早由中文维基的<a title="Zhengzhu on Wikipedia" href="http://adf.ly/M8a" target="_blank">Zhengzhu</a>同学发明.</p>
<p>最新版本: Version 1.1.4</p>
<ul>
<li>修复包括一个严重Bug在内的若干Bug.</li>
<li>大幅优化代码.</li>
<li>建议所有人更新到此版本.</li>
</ul>
<p>术语定义:</p>
<ul>
<li>页面原始版本: 即您博客页面的原始内容, 不进行中文繁简转换, 内容繁简共存. 这个页面URL就是您原来的Permalink.</li>
<li>中文转换版本: 本插件生成的页面版本, 把数据库中内容进行中文转换后输出. 输出的中文类型共六种: 简体中文(zh-hans), 繁体中文(zh-hant) , 台湾正体(zh-tw), 港澳繁体(zh-hk), 马新简体(zh-sg)和大陆简体(zh-cn).</li>
</ul>
<p>特性(Features):</p>
<ul>
<li>繁简转换页面URL支持<code>/permalink/to/your/original/post/?variant=zh-xx</code>和  <code>/permalink/to/your/original/post/zh-xx/</code>两种形式.(zh-xx为语言代码)</li>
<li>基于词语繁简转换. 如 “网络” 在台湾正体(zh-tw)里会被转换为 “網路”.</li>
<li>自动在转换后版本页面加上noindex的meta标签, 避免搜索引擎重复索引.</li>
<li>使用Cookie保存访客语言偏好. 插件将记录浏览者最后一次访问时的页面语言, 在浏览者再次访问显示对应版本. (此功能默认不开启)</li>
<li>自动识别浏览器语言. 插件将识别用户浏览器首选中文语言, 并显示对应版本页面. (此功能默认不开启)</li>
<li>中文搜索关键词简繁体通用. 这将增强Wordpress的搜索功能, 使其同时在数据库里搜索关键词的简繁体版本. 例如, 假如访客在浏览您博客页面时通过表单提交了关键词为 “網路” 的搜索, 如果您的文章里有 “网络” 这个词, 则这篇文章也会被放到搜索结果里返回. (此功能默认不开启)</li>
<li>后台可设置不转换部分HTML标签里中文.</li>
<li>Self-documented codes, easy to modify base your own needs.</li>
</ul>
<p>如果使用缓存插件 (WP Super cache, Hyper Cache, etc), 上面部分功能(识别浏览器语言, 使用Cookie保存访客语言偏好)将失效. 在以后的版本里可能加入对缓存插件的支持.
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：基于维基百科的WordPress全站中文繁简转换插件<br />发表日期：2009年07月27日<br />原文链接：<a href="http://xirang.us/2009/07/wordpress-chinese-conversion-plugin" >http://xirang.us/2009/07/wordpress-chinese-conversion-plugin</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=837&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2009/07/wordpress-chinese-conversion-plugin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>为跨平台数据库引擎 SQLite 实现加密扩展</title>
		<link>http://xirang.us/2009/07/encrypt-sqlite</link>
		<comments>http://xirang.us/2009/07/encrypt-sqlite#comments</comments>
		<pubDate>Sun, 12 Jul 2009 14:22:33 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=149</guid>
		<description><![CDATA[使用开源的 SQLite C++ warpper 项目- wxSQLite3 来实现 SQLite 数据库引擎的加密扩展。]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2009/07/encrypt-sqlite#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p><span style="color: #ff6600;">站长提示：如果您点击本文中的链接后出现了广告画面，麻烦您等待5秒后点击右上角的</span><strong>SKIP AD</strong><span style="color: #ff6600;">按钮跳过广告继续查看链接内容。对您造成的不便我们深感歉意，但是这一点微薄的广告收入可以维持本站的正常运作，全站作者由衷地感谢您的谅解与支持。</span><br />
<hr size="1" color="#bd1016"/></p>
<h3>SQLite 简介</h3>
<p><a title="维基百科：SQLite" href="http://zh.wikipedia.org/wiki/SQLite" target="_blank">SQLite</a> 是非常优秀的跨平台数据库引擎。与最常见的需要服务进程的数据库引擎（如 <a title="维基百科：MySQL" href="http://zh.wikipedia.org/wiki/MySQL" target="_blank">MySQL</a> ）不同，SQLite 引擎不是独立的<a title="维基百科：进程" href="http://zh.wikipedia.org/wiki/进程" target="_blank">进程</a>，而是与主程序编译在一起、并运行在同一个进程空间中的代码。数据的存取则是通过程序内直接调用其 <a title="维基百科：API" href="http://zh.wikipedia.org/wiki/API" target="_blank">API</a> 实现的，整个数据库都在宿主主机上存储在一个单一的文件中。这些使得 SQLite 在读写效率、消耗总量、延迟时间和整体简单性上具有很大的优越性。<span id="more-149"></span></p>
<p>最为重要的的是，整个 SQLite 引擎是一个相对小规模的轻量级 C 语言库。理论上说，任何平台，只要有 C 语言编译器，SQLite 就能够移植到该平台上。又由于其轻量性，SQLite 成为了处理器性能、内存容量上都相对有限的嵌入式平台数据库的最佳解决方案（如 Google 的开源手机平台 <a title="维基百科：Android" href="http://zh.wikipedia.org/wiki/Android" target="_blank">Android</a>）；同时也是中小规模 <a title="维基百科：内容管理系统" href="http://zh.wikipedia.org/wiki/内容管理系统" target="_blank">CMS</a> 系统数据库的良好解决方案；当然，PC 上的软件，也大量的采用了 SQLite （如 <a title="维基百科：Firefox" href="http://zh.wikipedia.org/wiki/Firefoxhttp://" target="_blank">Firefox</a>）。</p>
<p>不过，SQLite 有一个致命的缺点：免费版并不能对数据库进行加密。也就是说，这个存储于本地的数据库文件，如果用任何文本编辑器打开，数据内容便一览无余……相当的可怕吧，想想如果<a title="嘻来嚷往" href="http://xirang.us" target="_self">嘻来嚷往</a>使用未加密的 SQLite 来存储数据，各位用户的密码那就是垂手可得啦，哈哈哈，说不准你就使用的跟银行帐户一样的密码。不过呢站长 Tim 是非常负责滴，<a title="维基百科：WordPress" href="http://zh.wikipedia.org/wiki/WordPress" target="_blank">WordPress</a> 是非常强大滴，密码在存入数据库之前已经通过 WordPress 程序经过不可逆加密，就算能看到这些密码，也是一堆乱七八糟的东西。</p>
<h3>给 SQLite 上把锁</h3>
<p>作为一个著名的开源项目和著名的数据库，SQLite 的作者不可能没有想到数据加密的问题。其实作者只是留下了接口sqlite3_key而没有实现，这也给使用者更大的空间来用自己需要的算法加密数据。</p>
<p>密码学是一个庞大复杂的学科，普通的数据库开发者不可能为了加密 SQLite 而耗费大量时间去学习这门学科，我们只需要在sqlite3_key接口中调用一些加密API即可（如OpenSSL）。如果你是Windows开发人员，你也可以使用.net提供的加密函数。这样虽然免去了自己编译、学习OpenSSL的麻烦，不过也使得 SQLite 失去了跨平台的优势。</p>
<p>这里，<a title="Tim 在嘻来嚷往上的所有文章" href="http://xirang.us/author/tim/" target="_blank">Tim</a> 要介绍的是 <a title="SourceForge" href="http://adf.ly/MJs" target="_blank">SourceForge</a> 上的一个开源项目 <a title="wxSQLite3" href="http://adf.ly/MJu" target="_blank">wxSQLite3</a>，这一个兼具易用性和可移植性的 SQLite 加密解决方案。作者采用了比日益衰老的 <a title="DES" href="http://zh.wikipedia.org/DES" target="_blank">DES</a> 更为先进的使用 Rijndael 算法的 <a title="AES" href="http://zh.wikipedia.org/wiki/%E9%AB%98%E7%BA%A7%E5%8A%A0%E5%AF%86%E6%A0%87%E5%87%86" target="_blank">AES</a>（<a title="退出 DES，进入 Rijndael" href="http://adf.ly/MJv" target="_blank">退出 DES，进入 Rijndael</a>）实现了 SQLite 的加密接口。下面就开始编译加密 SQLite 库前的准备工作吧。</p>
<ol>
<li>首先，到SQLite 官方网站 &#8211; <a title="SQLite" href="http://adf.ly/MJw" target="_blank">http://www.sqlite.org/</a>的<a title="下载SQLite" href="http://adf.ly/MJx" target="_blank">download</a>页面，下载 SQLite 源码：sqlite-source-x.zip（其中x代表当前的版本号）。注意：不要下载前面的sqlite-amalgamation-x.zip，这是把所有源文件合成单个C文件的源码包，wxSQLite 需要独立源文件的源码，否则你要修改 wxSQLite 源码才能编译成功；</li>
<li>接着，到wxSQLite 项目 &#8211; <a title="wxSQLite3" href="http://adf.ly/MJu" target="_blank">http://wxcode.sourceforge.net/components/wxsqlite3/</a>主页下载 wxSQLite3 最新的release版本。</li>
</ol>
<p>准备工作就绪后，解开 wxSQLite3 的源码包你可以看到sqlite3子目录，这个目录下现有的代码就是对 SQLite 加密接口的 Rijndael 算法实现。将这些代码编译进入 SQLite 库，你有两种选择：</p>
<p><span style="color: #ff0000;">注意：这两种选择，在您最后一道编译时，切记都要在编译参数中开启SQLITE_HAS_CODEC的宏定义，否则即使你调用了sqlite3_key，数据库也得不到加密！</span></p>
<ol>
<li>动态链接 SQLite 库：首先解开 SQLite 源码包，用你所使用的平台的 C 编译器将 SQLite 编译成动态链接库。接着将编译好的库文件拷贝到 wxSQLite3 源码的 sqlite3/lib 目录，将 SQLite 的头文件拷贝至 sqlite3/include 目录。接着，在你的编译器的编译选项里加入对这些头文件的包含以及刚刚编译号的 SQLite 库的链接，继续编译 sqlite3\secure\src\codec 下的代码。如果一切顺利，一个动态链接的 AES 加密 SQLite 引擎库就产生了。</li>
<li>静态链接 SQLite 库：同动态链接，先把 SQLite 的头文件拷贝至sqlite3/include 目录，接着将 SQLite 的c文件拷贝至sqlite3/secure/src。接着你需要自己编写makefile，设置宏USE_DYNAMIC_SQLITE3_LOAD的值为0，最后编译包括 sqlite3\secure\src\codec 中的所有代码。一切顺利，一个静态的 AES 加密 SQLite 引擎库就产生了。</li>
</ol>
<p>到这里，你就可以在你的程序中使用这个 AES 加密的 SQLite 库了。加密您的数据库的方法，就是在打开的数据库后，在进行读写操作前，用自己指定的密匙调用 SQLite 的加密函数：<br />
[cc lang="c"]sqlite3_key(pdb, “XLRW”, 4);[/cc]<br />
其中，pdb是刚刚打开的数据库的指针，XLRW是密匙，4代表密匙长度。这时候，你再用文本编辑器打开 SQLite 的数据库文件，那就是一本天书啦。</p>
<h3>编译 SQLite 的 C++ warpper &#8211; wxSQLite3</h3>
<p>最后还是要提一下 wxSQLite3 到底是什么。其实 wxSQLite3 是一个 SQLite 的 C++ warpper，只是它只是顺带将 SQLite 的加密函数实现了。如果你是一个 C++ 开发者，又喜欢使用 STL 的迭代器模式进行数据访问，那么接下来，推荐你通过链接刚刚编译好的加密 SQLite 库，来编译以 C++ STL 迭代器方式访问 SQLite 数据库的 wxSQLite3 库。wxSQLite3的源代码是 src\wxsqlite3.cpp 。具体如何编译，笔者就不再赘述。
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：为跨平台数据库引擎 SQLite 实现加密扩展<br />发表日期：2009年07月12日<br />原文链接：<a href="http://xirang.us/2009/07/encrypt-sqlite" >http://xirang.us/2009/07/encrypt-sqlite</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=149&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2009/07/encrypt-sqlite/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>编译Windows平台下真正意义上的静态Qt库</title>
		<link>http://xirang.us/2009/06/qt-static</link>
		<comments>http://xirang.us/2009/06/qt-static#comments</comments>
		<pubDate>Fri, 26 Jun 2009 14:30:00 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[信息时代]]></category>
		<category><![CDATA[编程开发]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[静态库]]></category>

		<guid isPermaLink="false">http://xirang.us/?p=29</guid>
		<description><![CDATA[我在国内外Qt论坛上看到的最多的问题之一就是如何编译静态Qt库，可见在动态链接库(Windows: .dll, Linux: .so)大势所趋的今天，静态链接库还是具有其存在的合理性和广泛需求。]]></description>
			<content:encoded><![CDATA[<p>本文发表在<a href="http://xirang.us" target="_blank">嘻来嚷往国际版</a>，作者<a href="http://xirang.us/author/tim" target="_blank">Tim</a>。您可以<a href="http://xirang.us/2009/06/qt-static#comments" target="_blank">参与本文评论</a>或是follow本站的<a href="https://twitter.com/xirang" target="_blank" title="嘻来嚷往官方Twitter">Twitter帐号</a>。<br />
<hr size="1" color="#bd1016"/></p>
<p>我在国内外<a title="维基百科：Qt" href="http://zh.wikipedia.org/wiki/Qt" target="_blank">Qt</a>论坛上看到的最多的问题之一就是如何编译静态Qt库，可见在动态链接库 (Windows: .dll, Linux: .so)大势所趋的今天，静态链接库还是具有其存在的合理性和广泛需求。首先看看动态库给我们带来了什么：</p>
<ol>
<li>开发时的复用性：成千上万的各种实用库，包含它们的头文件，你就可以开始使用它们提供的功能；</li>
<li>编译时的快捷化：进行过静态链接编译的人都知道，其编译过程的时间消耗是动态链接的数倍倍甚至更多；</li>
<li>部署时的轻量化：如果你的程序使用操作系统自带的动态库，或者是一些非常流行的库。那么部署你的软件时，这些库便可以不用包含在你的packge里面，大大减小了其体积；</li>
<li>使用时的可维护性：某个库如果发布了更新的版本，那么你只需替换这个动态库文件，而不需要重新编译你的整个程序。<span id="more-29"></span></li>
</ol>
<p>在如今这个时不时都需要给软件打补丁的时代，这是相当方便的。那么，她又会给我们带来什么烦恼呢？<strong>软件的易用性至上</strong>。所谓易用性，不单单指这个进入了这个软件后使用起来多么多么方便，使用之前的那些过程同样也是易用性的一部分。</p>
<p>用过<a title="维基百科：Linux" href="http://zh.wikipedia.org/wiki/Linux" target="_blank">Linux</a>的可能都会有同感，装个软件真难啊，一会儿提示缺这个so库，一会儿这个so和那个so又不兼容了，还有甚者，你还需要在你的帐户的配置文件里设置一大堆参数……还没安装完，就已经放弃了使用这个软件的念头。我想，易用性的问题也是 Linux如此强大可是普及率远远不及Windows的根源吧，毕竟绝大多数的用户需要的是一个傻瓜相机般的操作系统。</p>
<p>不过在Windows下，常常你也会遇到”某个dll无法找到，程序无法启动”、”需要.net framework”之类的提示之。懂点软件知识的，还知道去下载这个缺失的dll库或者是下载.net的再发行库来安装。但是这已经大大违背了<strong>软件易用性</strong>的原则，要知道软件的受众绝大多数都是与IT行业无关的人员，它们遇到这些问题时候便是束手就擒。</p>
<p>Visual Studio 2005后的版本更是不可理喻，它们编译出来的C/C++程序，如果在没有Visual Studio再发行库的系统上运行，直接提示”应用程序没有正确配置，重新安装可能解决该问题”，简直不知所云……</p>
<p>静态链接的存在的合理性就在这里，一个可执行文件部署给用户，用户什么都不用做，双击一下就可享用。至于编译、维护，那是开发者的事情，哪怕一次编译要耗费一天的时间，也不能浪费用户的时间去做一些对他来说不知所云而本可以在开发者的环节中完成的事情。基于以上的信念，我研究了Windows下真正意义上的Qt静态库编译方法。至于什么叫”真正意义上”，看了下文便知。</p>
<h2>Visual Studio相关编译选项</h2>
<p>自己动手编译过Qt的人可能会觉得奇怪，拿这个问题来写这么一大段，真是小题大作。Qt的配置选项中不是写得清楚明白-static便是编译静态库吗。可是你有真正试过吗，用这个静态库编译的程序拿到一个”干净”的机器上运行，则提示”应用程序没有正确配置……”或是”msvcrpxx.dll”没有找到。 看来Qt是静态了，可是Qt是用C++写的，其中链接的C++运行库还是动态的。解决这个问题，要从Visual Studio的4个编译选项说起，它们决定了程序在链接阶段C/C++库的链接方式。</p>
<p><strong>1.链接C/C++多线程动态库，使用这些编译选项，软件部署时<span style="COLOR: #ff0000">需要</span>VC的再发行库，否则就会出现上述错误提示。</strong></p>
<p>/MD：动态链接多线程库(msvcrt.lib)。使用该选项时，需要用/NODEFAULTLIB选项来忽略掉libc.lib、libcmt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib库，否则会有链接错误;</p>
<p>/MDd：动态链接多线程调试库(msvcrtd.lib)。使用该选项时，需要用/NODEFAULTLIB选项来忽略掉libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib库，否则会有链接错误；</p>
<p><strong>2.链接C/C++多线程静态库，使用这些编译选项，软件部署时<span style="COLOR: #ff0000">不需要</span>VC的再发行库。</strong></p>
<p>/MT：静态链接多线程库(libcmt.lib)。使用该选项时，需要用/NODEFAULTLIB选项来忽略掉libc.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib库，否则会有链接错误;</p>
<p>/MTd：静态链接多线程调试库(libcmtd.lib)。使用该选项时，需要用/NODEFAULTLIB选项来忽略掉libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、msvcrtd.lib库，否则会有链接错误。</p>
<p>OK，准备工作就绪，下面开始编译真正意义上的静态Qt库:-)</p>
<h2>编译静态Qt库</h2>
<p>既然找到了解决方法，这个编译就应该没问题了吧。可是configure时明明用-static配置了Qt，编译结果确仍然事与愿违。仔细查看所生成的 makefile，才发现编译选项都是/MD、/MDd。问题就出在这里啦，不过这成千上百个makefile，难道要手动一个个修改……一定有什么东西决定了makefile的生成参数。不错！就在Qt根目录中的mkspecs目录里，一看名字就知道是make specification的缩写。该目录下，各种平台下的各个编译器都有一个子目录。嘿嘿，编译器的编译选项就都在这里了，打开win32- msvc2008中的qmake.conf看看，找到了下面两行吗：<br />
[cc lang="make"]<br />
QMAKE_CFLAGS_RELEASE = -O2 -MD -GL<br />
QMAKE_CFLAGS_DEBUG = -Zi -MDd<br />
[/cc]<br />
相信你已经知道了问题答案，将它们改成：<br />
[cc lang="make"]<br />
QMAKE_CFLAGS_RELEASE = -O2 -MT -GL<br />
QMAKE_CFLAGS_DEBUG = -Zi -MTd<br />
[/cc]<br />
同时别忘了加入前面提到的忽略库选项，修改QMAKE_LFLAGS_RELEASE和QMAKE_LFLAGS_DEBUG参数为：<br />
[cc lang="make"]<br />
QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /LTCG /NODEFAULTLIB:libc.lib /NODEFAULTLIB:msvcrt.lib/NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib<br />
QMAKE_LFLAGS_DEBUG = /DEBUG /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:msvcrtd.lib<br />
[/cc]<br />
大功告成，这个时候再在Qt的根目录下configure -static &#8230;(其它选项自行选择)，然后nmake，两三个小时之后，真正意义上的静态Qt库就产生了。本人有个小建议，其实编译demos和examples 会消耗非常多时间，你只用cd src然后nmake来编译Qt库，如有需要cd tools来编译诸如QtDesigner之类的工具。另外webkit库的编译是最耗时的，如果你不准备使用这个库，那么configure加入 -no-webkit，这样，整个编译过程大概值耗时40－60分钟。这时候你可以尝试建立第一个纯静态的Qt程序，不过当你链接的时候，仍然会出现一大堆链接错误，提示 unresolved external symbol。这个时候你只需要在你的Qt工程文件.pro里面加入：<br />
[cc lang="make"]<br />
win32:LIBS += Imm32.lib Winmm.lib ws2_32.lib<br />
[/cc]<br />
即可。至此，你的”纯”静态Qt应用程序就可以发布给用户啦。
<div style="clear:both">
<h3>著作权信息（站外使用本文请保留以下内容）</h3>
<hr size="2" />
<table width="100%">
<tbody>
<tr>
<td>文章作者：<a  href="http://xirang.us/author/tim">Tim</a><br />原始站点：<a title="嘻来嚷往" href="http://xirang.us/" target="_self">嘻来嚷往 &#8211; IF YOU SEE SOMETHING, SAY SOMETHING.</a><br />原文标题：编译Windows平台下真正意义上的静态Qt库<br />发表日期：2009年06月26日<br />原文链接：<a href="http://xirang.us/2009/06/qt-static" >http://xirang.us/2009/06/qt-static</a></td>
<td class="author_img"><center><img alt='' src='http://0.gravatar.com/avatar/6f9a9d5526438d3a59313a2603020217?s=100&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D100&amp;r=R' class='avatar avatar-100 photo' height='100' width='100' /></center></td>
</tr>
<tr>
<td>版权协议：本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/" target="_blank">知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议</a>进行许可，作品中的文字和图像若非明确指出著作权归属则均受到该协议<a title="知识共享协议法律文本" href="http://creativecommons.org/licenses/by-nc-nd/2.5/cn/legalcode" target="_blank">法律文本</a>的保护。站外使用请严格遵守协议，<a href="http://xirang.us/" target="_self">嘻来嚷往</a>站保留诉诸法律的权利！如有异议请与站长<a title="联系我们" href="http://xirang.us/affairs" target="_self">联系</a>。</td>
<td><center><img src="http://i.creativecommons.org/l/by-nc-nd/2.5/cn/88x31.png" alt="BY-NC-ND" /></center></td>
</tr>
</tbody>
</table>
<hr size="2" /></div>
<p style="text-align:center"><a href="http://clustrmaps.com/counter/maps.php?url=http://xirang.us" id="clustrMapsLink" title="嘻来嚷往双站总独立IP访问量" target="_blank"><img src="http://clustrmaps.com/counter/index2.php?url=http://xirang.us" alt="" id="clustrMapsImg" /></a><img src="http://nojsstats.appspot.com/UA-9442677-1/xirang.us" alt="" /></p>
<img src="http://xirang.us/?ak_action=api_record_view&id=29&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://xirang.us/2009/06/qt-static/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
