<?xml version="1.0" encoding="GBK" ?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dcterms="http://purl.org/dc/terms/">
 <channel>
  	  <title><![CDATA[小和尚真情无限]]></title>
	  <link>http://liufabin66688.blog.163.com</link>
	  <description><![CDATA[喜欢交朋友 学会正确的思考everything，让自己在进化树上爬得更高]]></description>
	  <language>zh-CN</language>
	  <pubDate>Thu, 17 Sep 2009 00:40:01 +0800</pubDate>
	  <lastBuildDate>Thu, 17 Sep 2009 00:40:01 +0800</lastBuildDate>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <generator><![CDATA[NetEase Space]]></generator>
	  <managingEditor><![CDATA[liufabin66688]]></managingEditor>
	  <webMaster><![CDATA[ 小和尚]]></webMaster>
		  <ttl>120</ttl>
	  <image>
	  	<title><![CDATA[小和尚真情无限]]></title>
	  	<url>http://ava.bimg.126.net/photo/vdGC02PbGQbTip2UhY3W3A==/429249339484679637.jpg</url>
	  	<link>http://liufabin66688.blog.163.com</link>
	  </image>
  <item>
  	<title><![CDATA[算法世界的哲学思考]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200981703947568</link>
    <description><![CDATA[<div><p><strong>每每读到一些好的算法都会让人有叹为观止的感觉</strong>，巧妙的设计让我们回味起数学，物理等，物理的测万有引力，远古
时代没有任何工具的情况下的测量出地球的半径，人就是这么一个奇妙的动物。想体味下巧妙，你可以看下《啊哈，灵机一动》google黑板报的《数学之美》
系列，微软的《编程之美》等，大道至简，简单的道理抽象到了一定的高度就适应于任何事物，在我看来数学和哲学都是抽象到一定程度的事物，你可以体味下
1+1=2，事物的都是有联系的普遍性。俗话说大道至简。<br>
读计算机以来，自然也学到不少算法，虽然现在搞些web的开发，当初也是软件开发的，总是忘不了学过的那些经典的算法，经常及其老师讲解时候的费力和樯橹灰飞烟灭。自己体味好多计算机里面的算法，定理，思想，更大自然世界很协调。<br>
先举几个简单的小例子：<br>
1 将两只小猫放到足球场的对面，相距100码，他们以每分钟10码的速度相向行走。同时这两只小猫的母亲在足球场的一端，它可以以每分钟100码的速度跑步，猫妈妈从一只小猫跑到另一只小猫，来回轮流跑而速度不减，一直跑到两只小猫在中场相遇，问猫妈妈跑了多远？<br>
2 渔民在池塘放养了大量鱼苗。养到一定程度后，我们要估计现在池塘中有多少鱼？<br>
3
有一根27厘米的细长杆，在第3厘米，7厘米，11厘米，17厘米，23厘米在五个位置各放有一只蚂蚁，木杆很细，不能同时通过两次蚂蚁，开始时，蚂蚁头
朝右还是朝左是任意的，他们只会超前或者调头，当不会后退。当任意两只蚂蚁碰头时，两只蚂蚁会同时掉头朝反方向走，假设蚂蚁每秒钟可以走一厘米的距离，所
有蚂蚁离开木杆的最短时间和最长时间。<br>
4 棋盘覆盖问题。在一个2k x 2k ( 即：2^k x 2^k
)个方格组成的棋盘中，恰有一个方格与其他方格不同，称该方格为一特殊方格，且称该棋盘为一特殊棋盘。在棋盘覆盖问题中，要用图示的4种不同形态的L型骨
牌覆盖给定的特殊棋盘上除特殊方格以外的所有方格，且任何2个L型骨牌不得重叠覆盖。</p>
<p><img title="1005341" src="http://www.5aicha.com/wp-content/uploads/2009/09/1005341.gif" alt="1005341" height="117" width="122"></p>
<p>5 某一天，一个新研究员向托马斯爱迪生报到。爱迪生要求他计算出一个空灯泡壳的体积。在使用测径仪和微积分进行数小时饿计算后，这个新员工给出了答案150立方厘米，而爱迪生在几秒之内计算就给出了更接近155，他是如何实现的呢？</p>
<p>—————————————-给出部分提示————————–</p>
<p>1 不要用蛮力，首先通过两只小猫可以计算出猫妈妈的跑步的时间，两只小猫相距100米，每分钟20码在接近，故5分钟完成，所以猫妈妈是500米</p>
<p>2 这个牵涉到数学中的概率等的知识，概率统计还是挺实用的一门学科，可以考虑用极大似然估算算法，即捞出一定数量的鱼，不能过少，坐上标记，过一定时间取出看看标记的比例</p>
<p>3 和第一个的思想有点像，碰头后蚂蚁会继续潜行，看做是个体运动就好考虑了</p>
<p>4 第四题图片方格少，还好，如果多了，你就不一定能搞定了，还需保证是4的k次幂，其实可以采用分治的思想，即图上可以上下左右四部分，带黑色宽那个就可以填好了，挨着黑色块的即中心的可以填好了，然后就把其他的搞定，如果更多如何？就行切分，分治，分而治理。</p>
<p>5 想想阿基米德王冠的故事你就明白了</p>
<p>现在可以看到了</p>
<p>一题三给我们一个解决问题的思路用时间求解较容易，摊还分析就是用这样一个思路，一如一个附加变量，位势，</p>
<p>二题，五题也是给我们一种思路转换问题的思路。4题给我们一个解决问题分而治之。</p>
<p>可以看到什么样的哲学思想呢？首先事物是联系的，解决了这个事物，和其关系的别的也就可以相应的解决了，整体和局部的思想，局部解决了，整体也就好了。</p>
<p>看看别的算法</p>
<p>1 递归于分治策略，递归？现实生活中哪里有递归的影子？没想到？那就照照镜子吧，看到了，这个就是递归，事物本身的属性，局部整体的哲学思想</p>
<p>2 动态规划，类似分治递归，当他们的若干个问题不是独立的是联系的，第n个问题和n-1个问题是有关系的，</p>
<p>3 贪心算法很明晰矛盾分主要矛盾和次要矛盾，抓住了主要矛盾就抓住了问题的核心</p>
<p>4 概率算法：事物发展的不确定性，螺旋式发展。舍伍德算法，拉斯维加斯算法，我们经典的抛针算π的算法，蒙特卡洛算法，现在基本都忘记了。</p>
<p>5 线性规划，回溯法，分枝限界法 这些都是通过把问题抽象，合理的布局，解决之，算是事物之间的联系吧。别的暂时没行到。</p>
<p>6np完全性理论和近似算法：图灵机等，应该是事物的发展变化的各个状态，著名的图灵机问题，问题的各个态势的变化，这个算法我不熟。</p>
<p>暂时先想到这里，也算是对自己学过的算法课程的一个回忆。</p></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200981703947568</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200981703947568</guid>
    <pubDate>Thu, 17 Sep 2009 00:39:47 +0800</pubDate>
    <dcterms:modified>2009-09-17T00:39:47+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[批量替换文件夹下所有文件内容脚本(shell,php,python)]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200981503216413</link>
    <description><![CDATA[<div><p>批量替换一个文件夹下的字符或者其他的应该经常可以见到，近期读《卓有成效的程序员》有点感触，他提到了一些可以加快工作效率的容易让人忽略的小细
节，加速法则，专注法则，自动化
法则，规范化法则。那这个批量替换应该属于自动化法则，有时候文件特别多的是很，替换是个非常容易烦人的事情。显然这些应该是计算机做的事情，下面给出以
上三个版本：</p>
<p>shell:</p>
<p>shell学了个皮也不皮，毛也不毛</p>
<p>for i in `find . -name “*.html”`<br>
do<br>
sed “s|&lt;\!–{if
\!empty(\$this-&gt;_visiteduser-&gt;_gender)&amp;&amp;
\(\$this-&gt;_visiteduser-&gt;_gender\)==’m'}–&gt;他&lt;\!–{else}–&gt;
她&lt;\!-&nbsp; -{/if}–&gt;|{\1}|g” $i &gt; $i-new<br>
mv $i $i-old<br>
mv $i-new $i<br>
done</p>
<p>当然你可以用sed的i直接替换，尽量替换前做个备份。</p>
<p>python的批量替换脚本：</p>
<p>刚开始学写的特别烂:</p>
<p>imp<wbr>ort os<br>
imp<wbr>ort re<br>
def getHtmlFile(rootdir):<br>
allfile=[]<br>
for&nbsp;&nbsp; parent, dirnames, filenames&nbsp;&nbsp; in&nbsp;&nbsp; os.walk(rootdir):<br>
for&nbsp;&nbsp; filename&nbsp;&nbsp; in&nbsp;&nbsp; filenames:<br>
#if os.path.isfile(os.path.join(0)<br>
allfile.append(os.path.join(parent, filename))<br>
return allfile</p>
<p>def replace(filename):<br>
file_object = open(filename)<br>
try:<br>
all_the_text = file_object.read( )<br>
finally:<br>
file_object.close( )<br>
”’<br>
grouped_word = re.compile(’&lt;div id=”header”&gt;([\s\S]*)?&lt;/div&gt;’)<br>
all_the_text = re.sub(r’xxxxxxxxxxxxxxxxxx’,all_the_text);<br>
”’<br>
all_the_text = re.sub(’&lt;div id=”header”&gt;[\s\S]+?&lt;/div&gt;’,'header’,all_the_text);<br>
all_the_text = re.sub(’&lt;div id=”footer”&gt;[\s\S]+?&lt;/div&gt;’,'footer’,all_the_text);<br>
#all_the_text = re.sub(’\r’,”,all_the_text);<br>
open(filename, ‘w’).write(all_the_text)</p>
<p>file=getHtmlFile(’/home/liufb/studypython/gonglue’);<br>
test = re.compile(”\.html$”, re.IGNORECASE)<br>
file = [f for f in file if test.search(f)]<br>
for i in file:<br>
print i+”\n”<br>
replace(i)</p>
<p>学的时间相对比较长，但是依旧比较烂：</p>
<p>function changefile($filename) {<br>
global $text1;<br>
global $text2;<br>
$file = file_get_contents($filename);<br>
$file2 = preg_replace(’@&lt;div id=”header”&gt;([\s\S]*)?&lt;/div&gt;@iU’,$text1,$file);<br>
$file3 = preg_replace(’@&lt;div id=”footer”&gt;([\s\S]*)?&lt;/div&gt;@iU’,$text2,$file2);<br>
$file3 = preg_replace(’@\r@iu’,”,$file3);<br>
file_put_contents($filename,$file3);</p>
<p>}<br>
function getFile($dirname) {<br>
if ($handle = opendir($dirname)) {<br>
while (false !== ($file = readdir($handle))) {<br>
if ($file != “.” &amp;&amp; $file != “..”) {<br>
$file=$dirname.’/’.$file;<br>
if(is_file($file) &amp;&amp; substr($file,-5) ==’.html’) {<br>
//echo $file.”\n”;</p>
<p>changefile($file);<br>
}else if(is_dir($dirname.’/’.$file)) {<br>
$dirscan = realpath($file);<br>
//$dirscan = $dirname.’/’.$file;<br>
//echo $dirscan.”\n”;<br>
getFile($dirscan);<br>
}<br>
}<br>
}<br>
}<br>
closedir($handle);<br>
}<br>
getFile(’.');</p></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200981503216413</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200981503216413</guid>
    <pubDate>Tue, 15 Sep 2009 00:32:16 +0800</pubDate>
    <dcterms:modified>2009-09-15T00:32:16+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[博客更新]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/1396854820098491734352</link>
    <description><![CDATA[<div>暂时这段时间的博客更换到：<br><a href="http://www.5aicha.cn/" target="_blank">http://www.5aicha.cn</a><br><a href="http://www.5aicha.com/" target="_blank">http://www.5aicha.com</a><br>有友情链接的麻烦更换。谢谢。<br><br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/1396854820098491734352</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/1396854820098491734352</guid>
    <pubDate>Fri, 4 Sep 2009 09:17:34 +0800</pubDate>
    <dcterms:modified>2009-09-04T09:18:18+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[我理解的中西方文明]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/139685482009726114823622</link>
    <description><![CDATA[<div><p>为什么华夏五千年的文明没有诞生大的科学，没有推动人类社会走向工业文明的社会的发展，为什么近代文明一次次的发展没有中国的影子？</p>
<p>我觉得应该从民族的思维形态和意识来探讨，总得讲西方的科学是一种质测的科学，是一种准确的科学，而中国的则是模糊的追求意境的一种算不上科学的科
学，从我们从小到大也应该感觉到我们教育的不足，就像别人说的主流的意思是一元化的成功，就是在校看成绩，走出学校看名利，社会也是那名利来认可判断一个
人的标准，所以在中国几千年的突然上倒是滋生了官场学问，对这些的追求成为带带不变的，“衣带渐宽终不悔，为伊消得人憔悴”，古代的一些借物用咏志者，官
场不得志者大有人在，我在想如果这些人都没有这些所谓的名利观念，研究下科学该多好。所以我认为几千年的文明贯穿的主线还是孔子的中庸之道，穷则独善其
身，达则兼并天下，当然在中国古代也有科学的发展，比如祖冲之的圆周率，徐光启，等寥若晨星，当他们永远是一小部分人的东西，很少能听说哪个朝代的大臣研
究这些的，诗经，论语，唐诗宋词元明曲
到成了我们的经典，当我们从这里有能学到什么呢？是的做人，但是在现实生活中广做人是不够的，还需要做事，孔子，老子，孙子代表了古典中最经典的文化，孔
子的教我们如何做人，老子具有了朴素的哲学思想，做什么事情都要有个度，而孙子呢？带给了我们《孙子兵法》，教我们做事，很明显我们大多数人忽视了孙子兵
法，但恕不知孙子兵法在世界上备受推崇，从日本的松下等企业的商战，到海湾战争，据说当时胡佛总统桌上两本书，一本就是孙子兵法，可见我们祖先的智慧还是
无穷的，当我们却很少去研究利用他们，看孙子兵法你可以看到好多闪光点，譬如兵势篇，我觉得很有超前的思想，激水之疾，至于漂石者，势也；鸷鸟之疾，至于
毁折者，节也。是故善战者，其势险，其节短。势如NFEEC弩，节如发机。想想我们物理中学到的势能是不是被我们祖先的智慧说折服，还有很多，里面也有好
多的朴素的哲学思想，也有现代的博弈论的思想，毕竟是双方对战吗？这样一本经典的著作，有多少人关注呢？</p>
<p>中西文明还有一大差别是对文化的追求上，中国古典文学里大多追求的意境，经典的例子就是：“你问我爱你有深，月亮代表我的心，你去问一
问。。。。”，而西方这大多会肯定的说 “ I love u
”,这些都在思维方式的不同，哪一个切身的例子，比如以前我们在新光天地地下广场吃饭，经常会去找位置，找凳子，而一般我们去找凳子都会去问,”请问你的
凳子还有人做吗？”，而有一次一个老外有一次向我们借，则说“can&nbsp; I take the
chair”，本来那个凳子没人做，按照我们的习惯思维说，也没太清楚那个人说的话，以为他在说，凳子有人做吗？我们所no，其实相反，闹了一个不大的笑
话。这个就是我们思维习惯的不同，其实也是我们的逻辑体系的不同，看看爱因斯坦的话，爱因斯坦于1953年给斯威泽的信中说，“西方科学的发展是以两个伟
大的成就为基础的，即希腊哲学家发明的形式逻辑体系（在欧几里得几何学中），以及通过
系统的实验发现有可能找出因果关系（在文艺复兴时期）。在我看来，中国的贤哲没有走上这两步，那是用不着惊奇的。若是这些发现（在中国）全都做出来了，那
反倒是令人惊奇的事情。”爱因斯坦实际上指出了：近代科学的发展在方法论上需要两大发现，即“从一般到特殊”的演绎法和以实验为基础的“从特殊到一般”的
分析和归纳法。这些也就是我们的不同。</p>
<p>其实这些都与我们的文化息息相关比如我们的方块字文化和西方的字母文化是不同的，在疾驰的地铁上，你大眼一看就理解看出墙上的模糊的字，而如果是因
为英文，你必须完全看清楚才能下定义，这个就是我们的模糊的，而西方这是准确的，我们追求意境，他们追求质地，王国维的人间词话里对意境的讨论最多，词以
境界为最上，有境界则自成高格，自有名句。大家只知道拿破仑的血腥，不知道拿破仑也是一名数学家，与拉格朗日等经常讨论问题，著名的拿破仑三角形，还记得
以前读书的一个小细节，说笛卡尔的解析几何流行时，当时的贵族人人一本，很流行，他们觉得这个是一种荣耀，而且女王请笛卡尔给他们讲课，可见在西方文化中
他们人人对科学都很重视。</p>
<p>说说西方文明的发源地，源自于古代埃及巴比伦等地域，那时候他们有些地域每年分给奴隶的土地都受河流冲刷，尼罗河的赠礼和这个有关吗？忘记了，导致
他们每年要上交税等的不一样，就这样他们必须测量来决定上交的税等，这样就诞生了几何的雏形，也让人类产生了思考，对大自然的思考，对上帝的思考，一次次
的发展，泰勒斯人类上第一位科学家，托勒密等都在人类文明上作出了卓越的贡献，他们都带我们带入了对自然的思考，对现实世界的抽象，从毕达哥拉斯的勾股定
理的发现，对声乐的思考相处乐声和发生物体的长度有关，到无意间发现罪恶的根号2，无理数，又带入了我们进入了一次次的无穷的探索，毕达哥拉斯和后来的柏
拉图都为科学的发展和传播作出了巨大贡献，毕达哥拉斯学派，到欧几里德独立思考写出了《几何原本》，更加抽象了自然界，虽然是当时看来研究这些是得不到什
么，是纯粹的数学，不想中国的书中自有颜如玉，当他推动了人类文明的发展和进程，西方科学发展也遍地开放，文艺复兴等一次次锲机，走向了更远的地区，特别
是数学的发展，数次转行中心，从古希腊到高斯领头的哥廷根大学，到现在美国为中心的数学中心，拥向了一代代为人类做出卓越贡献的，阿基米德，欧拉，费马，
笛卡尔，乔治康拓，哥德尔，<span style="color: rgb(255, 0, 0);"><strong> </strong></span>伽罗瓦，哈牛顿，莱布尼茨，哈代，印度国宝拉马努金，庞加莱，希尔伯特，到现在的冯诺依曼，图灵，每一个名字都曾照亮了我们的人类的行程，太多太多。试想如果他们中有个一个是我们中国人会怎么样？</p>
<p>总之我的思想是以后我们民族应该引导我们学习西方的质测的科学，不止是读三字经，百家姓，也应该读读西方人的譬如《几何原本》，《什么是数学》《西方文化中的数学》，任何事物的精华值得我们去学习的，我们要汲取。也希望我们国家以后会诞生越来越多的科学牛人</p></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/139685482009726114823622</comments>
    <slash:comments>1</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/139685482009726114823622</guid>
    <pubDate>Wed, 26 Aug 2009 23:48:23 +0800</pubDate>
    <dcterms:modified>2009-08-26T23:48:23+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[c操作mysql和c++的stl的学习]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200972101237614</link>
    <description><![CDATA[<div>这里只贴出代码，可能写也写到5aicha。com，近期已经搬运到这个博客：<br>#include &lt;iostream&gt;<br>using std::cout;<br>using std::endl;<br>#include &lt;queue&gt;<br>int main() {<br><br>&nbsp; std::queue&lt; double &gt; values;<br>&nbsp; values.push(3.2);<br>&nbsp; values.push(4.3);<br>&nbsp; values.push(6.5);<br>&nbsp; values.push(5.3);<br>&nbsp; cout &lt;&lt;"poping from values";<br>&nbsp; while(!values.empty()) {<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; values.front()&lt;&lt;",\n";<br>&nbsp;&nbsp;&nbsp; values.pop();<br>&nbsp; <br>&nbsp; }<br>&nbsp; cout &lt;&lt;endl;<br>&nbsp; return 0;<br>}<br>&nbsp;c操作msql的代码，从插入，到取得结果都以及包含：<br>#include &lt;stdlib.c&gt;<br>#include &lt;stdio.c&gt;<br>#include "mysql.h"<br>int main(int argc,char *argv[]) {<br><br>&nbsp; MYSQL my_connection;<br>&nbsp; MYSQL_RES *res_ptr;<br>&nbsp; MYSQL_ROW sqlrow;<br>&nbsp; int res;<br>&nbsp; //inintal the mysql connection<br>&nbsp; mysql_init(&amp;my_connection);<br>&nbsp; //connect mysql<br>&nbsp; if(mysql_real_connect(&amp;my_connection,"localhost","root","123456","foo",0,NULL,0)) {<br>&nbsp;&nbsp;&nbsp; printf("Connection success\n");<br>&nbsp;&nbsp;&nbsp; //query your sql<br>&nbsp;&nbsp;&nbsp; res = mysql_query(&amp;my_connection,"insert into children(fname,age) values ('anaa',3)");<br>&nbsp;&nbsp;&nbsp; if(!res) {<br>&nbsp;&nbsp;&nbsp; &nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; printf("insert %lu rows \n",(unsigned long)mysql_affected_rows(&amp;my_connection));<br><br>&nbsp;&nbsp;&nbsp; }else {<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; fprintf(stderr,"insert error %d:%s\n",mysql_errno(&amp;my_connection),mysql_error(&amp;my_connection));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; //get insert content<br>&nbsp;&nbsp;&nbsp; res = mysql_query(&amp;my_connection,"select last_inert_id");<br>&nbsp;&nbsp;&nbsp; if(res) {<br>&nbsp;&nbsp;&nbsp; &nbsp; printf("select error :%s\n",mysql_error(&amp;my_connection));<br>&nbsp;&nbsp;&nbsp; }else {<br>&nbsp;&nbsp;&nbsp; &nbsp; res_ptr = mysql_user_result(&amp;my_connection);<br>&nbsp;&nbsp;&nbsp; &nbsp; if(res_ptr) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while((sqlrow = mysql_fetch_row(res_ptr))) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; printf("we inserted chidno %s \n",sqlrow[0]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mysql_free_result(res_ptr);<br>&nbsp;&nbsp;&nbsp; &nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; mysql_close(&amp;my_connection);<br>&nbsp; <br>&nbsp; }else {<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; fprintf(stderr,"Connection failed");<br>&nbsp;&nbsp;&nbsp; if(mysql_errno(&amp;my_connection)){<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp; fprintf(stderr,"insert error %d:%s\n",mysql_errno(&amp;my_connection),mysql_error(&amp;my_connection));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; <br>&nbsp; }<br><br><br>&nbsp; return EXIT_SUCCESS;<br><br>}<br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200972101237614</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200972101237614</guid>
    <pubDate>Fri, 21 Aug 2009 00:12:37 +0800</pubDate>
    <dcterms:modified>2009-08-21T00:12:37+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[又是一条分割线]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/1396854820097144743225</link>
    <description><![CDATA[<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 终于松了口气，可以暂时完结一段心头事，不像刚毕业时候的辞职，那时候感觉提着自己的行李回家，心里空了，淡淡的伤感，虽然已经定了下家。但还是感觉自己有点无助，渺小，可能我心里想的是如果我没有工作了，我还能做什么，打工，难道几十年的教育给我的也就是一份工作，而且是飘摇不定，我想我们应该反思真正的教育应该给我们什么，给我们坚定的生活信心，给我们的学习能力，就如写一个程序，让我们的程序更健壮，不在粗糙，我想人生也应该这样，现在看书的心境，和上学时候看书的心境完全不同，比如学数学，以前学微积分啊，导数啊，很明显目标就是拿的高分，别的很少想，而现在则不同，现在看些数学书感觉看的是数学家如何取解决一个问题，如果如思考问题，这将给我更大的启发。譬如学英语，以前完全就是为了考试的完形填空，短文改错，写作为拿高分，现在感觉学应该一个事很cool，特别是做计算机，搞技术的很多比较新的技术都是以英文开始，所以在这个信息化的时代，我们一定不能错过这个机会。读写英文的技术文档，技术书籍，我感觉还是有很大好处，即使有翻译但有些翻译的还是变了味，也许是因为一字翻译的失误，就会导致你对一个知识点的理解偏差。<br>&nbsp;&nbsp;&nbsp; 这个月除了忙工作相关的事情，研究技术少了点。不过还好看书的多了点，把自己很久都没看完的《什么是数学》看的差不多了，看完了留下最深的印象就是作者简洁的表达，但却是滴水不漏的定理的证明等，做数学本来就该这样，数学就是科学的基础。最有影响的是看了李笑来老师的《把时间当做朋友》感觉写的确实挺好，看书很少有这样的感觉，看完了就是震撼，好多次能触动最深处，带着我们进行深刻的思考，在我们思维的盲点给我们补习了一棵，虽然不能说以后行动上能带来多大的影响，但是至少我的思维更加开阔了，面对问题更加慎重了，也听过公司的一堂培训课，解决问题的结构化方法，老师从问题的定义，到问题解决后的总结经验教训的过程，虽然感觉太刻板了，但是还是能给我一点启发的。<br>&nbsp;&nbsp;&nbsp; 说是一条分割线，其实就是自己换了换工作，换了换心情，写下这个标题，只是希望自己能会一如既往的努力。剔除自己身上更多的毛病，从一个粗糙的我变的不在粗糙，再一步步进化。所以希望的这条分割线就是自己灵魂的分割线。总之以后又灵感的触动，要理解捕获它，不然稍逊即逝<br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/1396854820097144743225</comments>
    <slash:comments>2</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/1396854820097144743225</guid>
    <pubDate>Sat, 1 Aug 2009 16:47:43 +0800</pubDate>
    <dcterms:modified>2009-08-02T08:40:39+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[shell里面如何进行mysql的操作]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/139685482009684754268</link>
    <description><![CDATA[<div>参考并致谢：<br>http://bbs2.chinaunix.net/viewthread.php?tid=971798<br><br>下面这个是我学到的，并能操作分表后的多个数据表，根据你分表的数量，这样你可以进行批量修改表的结构等<br>#!/bin/bash<br>USER=username<br>PASS=password<br>MYSQL=your mysqlbin path<br>SQLOPT=" -u$USER -p$PASS -S/tmp/mysql-new.sock $@"<br>DBNAME=your databasename;<br>TABLENUMBER=80<br>mysql_opt() {<br>&nbsp; db_name=$1<br>&nbsp; sql_query=$2<br>&nbsp; $MYSQL $SQLOPT &lt;&lt; EOF<br>&nbsp;&nbsp;&nbsp; USE $db_name;<br>&nbsp;&nbsp; &nbsp;set names utf8;<br>&nbsp;&nbsp; &nbsp;$sql_query;<br>&nbsp;&nbsp; &nbsp;QUIT<br>EOF<br>}<br><br>for&nbsp; i in `seq 0 78`<br>do<br>mysql_opt $DBNAME "select * from blog_$i limit 2 \G;" <br><br>sleep 1;<br><br>done<br>如果是简单的执行一条语句，则可以：<br>mysql -uroot -padmin -e "$sql"</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/139685482009684754268</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/139685482009684754268</guid>
    <pubDate>Wed, 8 Jul 2009 16:07:54 +0800</pubDate>
    <dcterms:modified>2009-07-08T16:07:54+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[安装php的调试工具xhprof]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/1396854820096581647970</link>
    <description><![CDATA[<div>facebook出的一个php的调试工具：<br>相关文档在：http://mirror.facebook.net/facebook/xhprof/doc.html<br>http://pecl.php.net/package/xhprof<br>首先就是需要到http://pecl.php.net/package/xhprof下载，或者直接<br>wget http://pecl.php.net/package/xhprof<br>然后：<br>tar xzvf xhprof-0.9.2.tgz<br>cd xhprof-0.9.2<br>注意在安装前需要安装phpize如果没有安装<br>在ubuntu下可以apt-get install php5-dev<br>如果安装不上，则可以<br><br>
ubuntu 安装: <br>
apt-get install autoconf<br>
apt-get  install php5-dev<br>
<br>
centos 安装: <br>
yum install php-devel<br>
yum install  autoconf<br><br>安装完成后<br>root@liufabin-laptop:/opt/xhprof-0.9.2# cd extension/<br>root@liufabin-laptop:/opt/xhprof-0.9.2/extension# phpize<br>Configuring for:<br>PHP Api Version:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20041225<br>Zend Module Api No:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20060613<br>Zend Extension Api No:&nbsp;&nbsp; 220060519<br>下一步非常重要：<br>&nbsp; ./configure --with-php-config=/usr/bin/php-config<br>checking for grep that handles long lines and -e... /bin/grep<br>checking for egrep... /bin/grep -E<br>checking for a sed that does not truncate output... /bin/sed<br>checking for gcc... gcc<br>checking for C compiler default output file name... a.out<br>checking whether the C compiler works... yes<br>checking whether we are cross compiling... no<br>checking for suffix of executables... <br>checking for suffix of object files... o<br>checking whether we are using the GNU C compiler... yes<br>checking whether gcc accepts -g... yes<br>checking for gcc option to accept ISO C89... none needed<br>checking whether gcc and cc understand -c and -o together... yes<br>checking for system library directory... lib<br>checking if compiler supports -R... no<br>checking if compiler supports -Wl,-rpath,... yes<br>checking build system type... i686-pc-linux-gnu<br>checking host system type... i686-pc-linux-gnu<br>checking target system type... i686-pc-linux-gnu<br>checking for PHP prefix... /usr<br>checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64<br>checking for PHP extension directory... /usr/lib/php5/20060613+lfs<br>checking for PHP installed headers prefix... /usr/include/php5<br>checking for re2c... no<br>configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.<br>checking for gawk... no<br>checking for nawk... nawk<br>checking if nawk is broken... no<br>checking whether to enable xhprof support... yes, shared<br>checking for a sed that does not truncate output... (cached) /bin/sed<br>checking for fgrep... /bin/grep -F<br>checking for ld used by gcc... /usr/bin/ld<br>checking if the linker (/usr/bin/ld) is GNU ld... yes<br>checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B<br>checking the name lister (/usr/bin/nm -B) interface... BSD nm<br>checking whether ln -s works... yes<br>checking the maximum length of command line arguments... 1572864<br>checking whether the shell understands some XSI constructs... yes<br>checking whether the shell understands "+="... yes<br>checking for /usr/bin/ld option to reload object files... -r<br>checking how to recognize dependent libraries... pass_all<br>checking for ar... ar<br>checking for strip... strip<br>checking for ranlib... ranlib<br>checking command to parse /usr/bin/nm -B output from gcc object... ok<br>checking how to run the C preprocessor... gcc -E<br>checking for ANSI C header files... yes<br>checking for sys/types.h... yes<br>checking for sys/stat.h... yes<br>checking for stdlib.h... yes<br>checking for string.h... yes<br>checking for memory.h... yes<br>checking for strings.h... yes<br>checking for inttypes.h... yes<br>checking for stdint.h... yes<br>checking for unistd.h... yes<br>checking for dlfcn.h... yes<br>checking for objdir... .libs<br>checking if gcc supports -fno-rtti -fno-exceptions... no<br>checking for gcc option to produce PIC... -fPIC -DPIC<br>checking if gcc PIC flag -fPIC -DPIC works... yes<br>checking if gcc static flag -static works... yes<br>checking if gcc supports -c -o file.o... yes<br>checking if gcc supports -c -o file.o... (cached) yes<br>checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes<br>checking whether -lc should be explicitly linked in... no<br>checking dynamic linker characteristics... GNU/Linux ld.so<br>checking how to hardcode library paths into programs... immediate<br>checking whether stripping libraries is possible... yes<br>checking if libtool supports shared libraries... yes<br>checking whether to build shared libraries... yes<br>checking whether to build static libraries... no<br>configure: creating ./config.status<br>config.status: creating config.h<br>config.status: config.h is unchanged<br>config.status: executing libtool commands<br>nfig<br>这个是默认的目录，你可以按照自己安装的目录更改<br>然后make&amp;&amp;make install 然后make test<br>即可，然后找到php.ini<br>添加：<br><br>1241 [xhprof]<br>1242 extension=xhprof.so<br>1243 ;#<br>1244 ;# directory used by default implementation of the iXHProfRuns<br>1245 ;# interface (namely, the XHProfRuns_Default class) for storing<br>1246 ;# XHProf runs.<br>1247 ;#<br>1248 xhprof.output_dir=/opt/xhprof/<br>&nbsp;kilall -9 php<br>然后重启即可<br>你如果看到这个就算成功了<br><a href="http://img.bimg.126.net/photo/W-9Aa-8S2lj7HUOXYEpIVw==/3981745020549937455.jpg" target="_blank"><img title="安装php的调试工具xhprof -  小和尚 - 小和尚真情无限" alt="安装php的调试工具xhprof -  小和尚 - 小和尚真情无限" src="http://img.bimg.126.net/photo/W-9Aa-8S2lj7HUOXYEpIVw==/3981745020549937455.jpg"></a><br>然后添加测试脚本：<br><div ><div ><pre  style="font-family: monospace;"><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;?php</span><br>&nbsp;<br><span style="color: rgb(0, 0, 0); font-weight: bold;">function</span> bar<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$x</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>  <span style="color: rgb(177, 177, 0);">if</span> <span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$x</span> <span style="color: rgb(51, 153, 51);">&gt;</span> <span style="color: rgb(204, 102, 204);">0</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>    bar<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$x</span> <span style="color: rgb(51, 153, 51);">-</span> <span style="color: rgb(204, 102, 204);">1</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>  <span style="color: rgb(0, 153, 0);">}</span><br><span style="color: rgb(0, 153, 0);">}</span><br>&nbsp;<br><span style="color: rgb(0, 0, 0); font-weight: bold;">function</span> foo<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>  <span style="color: rgb(177, 177, 0);">for</span> <span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$idx</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(204, 102, 204);">0</span><span style="color: rgb(51, 153, 51);">;</span> <span style="color: rgb(0, 0, 136);">$idx</span> <span style="color: rgb(51, 153, 51);">&lt;</span> <span style="color: rgb(204, 102, 204);">2</span><span style="color: rgb(51, 153, 51);">;</span> <span style="color: rgb(0, 0, 136);">$idx</span><span style="color: rgb(51, 153, 51);">++</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>    bar<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$idx</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>    <span style="color: rgb(0, 0, 136);">$x</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(153, 0, 0);">strlen</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 255);">"abc"</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>  <span style="color: rgb(0, 153, 0);">}</span><br><span style="color: rgb(0, 153, 0);">}</span><br>&nbsp;<br><span style="color: rgb(102, 102, 102); font-style: italic;">// start profiling</span><br>xhprof_enable<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>&nbsp;<br><span style="color: rgb(102, 102, 102); font-style: italic;">// run program</span><br>foo<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>&nbsp;<br><span style="color: rgb(102, 102, 102); font-style: italic;">// stop profiler</span><br><span style="color: rgb(0, 0, 136);">$xhprof_data</span> <span style="color: rgb(51, 153, 51);">=</span> xhprof_disable<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>&nbsp;<br><span style="color: rgb(102, 102, 102); font-style: italic;">// display raw xhprof data for the profiler run</span><br><span style="color: rgb(153, 0, 0);">print_r</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$xhprof_data</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;<br><br>结果为：<br></span>Array<br>(<br>    [foo==&gt;bar] =&gt; Array<br>        (<br>            [ct] =&gt; 2<br>            [wt] =&gt; 15<br>        )<br><br>    [foo==&gt;strlen] =&gt; Array<br>        (<br>            [ct] =&gt; 2<br>            [wt] =&gt; 0<br>        )<br><br>    [bar==&gt;bar@1] =&gt; Array<br>        (<br>            [ct] =&gt; 1<br>            [wt] =&gt; 2<br>        )<br><br>    [main()==&gt;foo] =&gt; Array<br>        (<br>            [ct] =&gt; 1<br>            [wt] =&gt; 38<br>        )<br><br>    [main()==&gt;xhprof_disable] =&gt; Array<br>        (<br>            [ct] =&gt; 1<br>            [wt] =&gt; 0<br>        )<br><br>    [main()] =&gt; Array<br>        (<br>            [ct] =&gt; 1<br>            [wt] =&gt; 45<br>        )<br><br>)<br><br></pre></div></div><br><br>具体可以看文档<br><br><br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/1396854820096581647970</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/1396854820096581647970</guid>
    <pubDate>Sun, 5 Jul 2009 08:16:47 +0800</pubDate>
    <dcterms:modified>2009-07-05T08:16:47+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[同一台机器mysql--replication ]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/1396854820096565510976</link>
    <description><![CDATA[<div>参考文章：<br>1:http://www.howtoforge.com/on<wbr>e_machine_mysql_replication<br>2:http://robinwu.javaeye.com/blog/310839<br>如果机器上已经用apt-get install安装了mysql，则可以用以下方式去除<span><span><br>&nbsp;1 apt-get&nbsp;--purge&nbsp;remove&nbsp;mysql-server&nbsp; <br>2 </span></span><span>apt-get&nbsp;--purge&nbsp;remove&nbsp;mysql-common&nbsp; </span><br>创建文件夹/misu：<br><p >tar xzvf <span>/mysql-5.0.67.tar.gz</span>.tar.gz</p>
<p >cd /misc/<span>/mysql-5.0.67.tar.gz</span></p>
<p >./configure --prefix=/usr/local/mysql-master</p>
<p >make</p>
<p >make install</p>

<p >cd /usr/local/mysql-master/bin</p>
<p >./mysql_install_db</p>
(it will create a var folder )<br>
<p >cd ../var</p>
<p >cp /misc/<span>/mysql-5.0.67.tar.gz</span>/support-files/my-medium.cnf my.cnf</p>
<p >cd ..</p>
<p >groupadd mysql</p>
<p >useradd -g mysql mysql</p>
<p >chown -R root .</p>
<p >chown -R mysql var</p>
chgrp -R mysql<span><span></span></span><span></span><br><br><br>查看my.cnf<br><pre>[mysqld]<br><br>port = 3306<br><br>socket = /usr/local/mysql-master/mysql.sock<br><br><br><br>#skip-networking // we have skip this in our case as we are doing both master and slave on same machine.<br><br><br><br># Replication Master Server (default)<br><br># binary logging is required for replication<br><br>log-bin<br><br><br><br># required unique id between 1 and 2^32 - 1<br><br># defaults to 1 if master-host is not set<br><br># but will not function as a master if omitted<br><br>server-id = 1<br><br><br></pre><p >cd /usr/local/mysql-master/bin</p>
./mysqld_safe --defaults-file=/usr/local/mysql-master/var/my.cnf <pre><br></pre><h3>MySQL Slave:</h3><br>
Now extract mysql-4.1.12.tar.gz at different dir,<br>
<p >cd /opt/mysql-4.1.12</p>
<p >./configure --prefix=/usr/local/mysql-slave</p>
<p >make</p>
<p >make install</p>
<p >cd /usr/local/mysql-slave</p>
<p >cd bin</p>
<p >./mysql_install_db</p>       
      (it will create a var folder )<br>
<p >cd ../var</p>
<p >cp /opt/mysql-4.1.12/support-files/my-medium.cnf my.cnf</p>
<p >cd ..</p>
<p >groupadd mysql</p>
<p >useradd -g mysql mysql</p>
<p >chown -R root .</p>
<p >chown -R mysql var</p>
<p >chgrp -R mysql .</p>
<br>
Edit my.cnf in the var folder<br>
[mysqld]<br>
port  = 3307<br>
socket  = /usr/local/mysql-slave/var/mysql.sock<br>
<br>
#skip-networking<br>
<br>
server-id = 2<br>
<br>
# The replication master for this slave - required<br>
master-host = localhost<br>
master-user = slavedb<br>
master-password = q1w2e3r4t5<br>
master-port = 3306<br>


Now starts the mysql server by:<br>
<p >cd /usr/local/mysql-slave/bin</p><div  style="height: 250px;"><div >
<div align="center">










 


</div>
</div></div>
<p >./mysqld_safe --defaults-file=/usr/local/mysql-slave/var/my.cnf &amp;</p>

<h3>Configure Replication:</h3><br>
connect to mysql master by:<br>
<p >mysql --sock=/usr/local/mysql-master/mysql.sock</p>
<br>
<h2>Create account at master for slave:</h2><br>
<p >mysql&gt; GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO slavedb@"192.168.1.27/255.255.255.0" identified by 'q1w2e3r4t5';
Query OK, 0 rows affected (0.28 sec)</p>
<br>
connect to mysql slave by:<br>
<p >mysql --sock=/usr/local/mysql-slave/mysql.sock</p>
<br>
<p >mysql&gt; slave start;</p>
Query OK, 0 rows affected, 1 warning (0.04 sec)<pre><br></pre><br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/1396854820096565510976</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/1396854820096565510976</guid>
    <pubDate>Sun, 5 Jul 2009 06:55:10 +0800</pubDate>
    <dcterms:modified>2009-07-05T06:55:10+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[安装crawl,libevent,berkeley-db]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/1396854820096212441212</link>
    <description><![CDATA[<div>&nbsp;项目：http://www.monkey.org/~provos/crawl/<br>需要安装：libevent和Berkeley<br>先安装Berkeley<br>下载到：http://www.oracle.com/technology/software/products/berkeley-db/index.html<br>然后：tar xzvf&nbsp; db-4.7.25.tar.gz <br>比较简单的就是：<br>cd build_unix/<br>如果以gcc和g++编译的话,须执行#env CC=gcc CCC=g++ ../dist/configure，<br><p>编译.<br>../dist/configure --prefix=/opt/Berkeley<br>make<br>make install</p><p>最后：</p><p><span > #vi /etc/ld.so.conf
并将berkeleyDB的lib路径加到该文件的最后一行,这样才能找到并加载它的库文件.ld.so.conf是什么东西？它就是系统动态链接库的配
置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录/lib,/usr/lib除外)，各个目录名间以空白字符(空格，换
行等)或冒号或逗号分隔。</span></p><p><span >成功后，测试一段代码是否争：代码为：</span></p><p><span >编译：</span></p><p>gcc test.c -ggdb -I /opt/Berkeley/include/ -L/opt/Berkeley/lib/ -ldb -lpthread -o test.out<br><span >从网上找到的测试代码：红色部分是修改的</span></p><p><span >#include &lt;db.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;pthread.h&gt;<br><span style="color: rgb(255, 0, 0);">#include &lt;string.h&gt; //添加</span><br><br>/* DB的函数执行完成后，返回0代表成功，否则失败 */<br>void print_error(int ret)<br>{<br>&nbsp; if(ret != 0)<br>&nbsp;&nbsp;&nbsp; printf("ERROR: %s\n",db_strerror(ret));<br>}<br><br>/* 数据结构DBT在使用前，应首先初始化，否则编译可通过但运行时报参数错误 */<br>void init_DBT(DBT * key, DBT * data)<br>{<br>&nbsp; memset(key, 0, sizeof(DBT));<br>&nbsp; memset(data, 0, sizeof(DBT));<br>}<br><br>int&nbsp; main(){<br>&nbsp; DB *dbp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; DBT key, data;<br>&nbsp; u_int32_t flags;<br>&nbsp; int ret;<br><br>&nbsp; char *fruit = "apple";<br>&nbsp; int number = 15;<br><br>&nbsp; typedef struct customer<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; int c_id;<br>&nbsp;&nbsp;&nbsp; char name[10];<br>&nbsp;&nbsp;&nbsp; char address[20];<br>&nbsp;&nbsp;&nbsp; int age;<br>&nbsp; } CUSTOMER;<br>&nbsp; CUSTOMER cust;<br>&nbsp; int key_cust_c_id = 1;<br><br>&nbsp; cust.c_id = 1;<br>&nbsp; strncpy(cust.name, "javer", 9);<br>&nbsp; strncpy(cust.address, "chengdu", 19);<br>&nbsp; cust.age = 32;<br><br>&nbsp; /* 首先创建数据库句柄 */<br>&nbsp; ret = db_create(&amp;dbp, NULL, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; /* 创建数据库标志 */<br>&nbsp; flags = DB_CREATE;&nbsp; <br><br>&nbsp; /* 创建一个名为single.db的数据库，使用B+树访问算法，本段代码演示对简单数据类型的处理<br>&nbsp;&nbsp; * */<br>&nbsp; ret = dbp-&gt;open(dbp, NULL, "single.db", NULL, DB_BTREE, flags, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; init_DBT(&amp;key, &amp;data);<br><br>&nbsp; /* 分别对关键字和数据赋值和规定长度<br>&nbsp;&nbsp; * */<br>&nbsp; key.data = fruit;<br>&nbsp; key.size = strlen(fruit) + 1;<br>&nbsp; data.data = &amp;number;<br>&nbsp; data.size = sizeof(int);<br><br>&nbsp; /* 把记录写入数据库中，不允许覆盖关键字相同的记录<br>&nbsp;&nbsp; * */<br>&nbsp; ret = dbp-&gt;put(dbp, NULL, &amp;key, &amp;data,DB_NOOVERWRITE);<br>&nbsp; print_error(ret);<br><br>&nbsp; /* 手动把缓存中的数据刷新到硬盘文件中，实际上在关闭数据库时，数据会被自动刷新<br>&nbsp;&nbsp; *<span style="color: rgb(255, 0, 0);"> */</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">&nbsp; //dbp-&gt;sync();//注释掉没找到错误，注释掉后可以运行，原来的拷贝是中文错误</span><br style="color: rgb(255, 0, 0);"><br>&nbsp; init_DBT(&amp;key, &amp;data);<br><br>&nbsp; key.data = fruit;<br>&nbsp; key.size = strlen(fruit) + 1;<br><br>&nbsp; /* 从数据库中查询关键字为apple的记录<br>&nbsp;&nbsp; * */<br>&nbsp; ret = dbp-&gt;get(dbp, NULL, &amp;key, &amp;data, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; /* 特别要注意数据结构DBT的字段data为void<br>&nbsp;&nbsp; * *型，所以在对data赋值和取值时，要做必要的类型转换。<br>&nbsp;&nbsp; * */<br>&nbsp; printf("The number = %d\n", *(int*)(data.data));<br><br>&nbsp; if(dbp != NULL)<br>&nbsp;&nbsp;&nbsp; dbp-&gt;close(dbp, 0);<br><br>&nbsp; ret = db_create(&amp;dbp, NULL, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; flags = DB_CREATE;&nbsp; <br><br>&nbsp; /* 创建一个名为complex.db的数据库，使用HASH访问算法，本段代码演示对复杂数据结构的处理<br>&nbsp;&nbsp; * */<br>&nbsp; ret = dbp-&gt;open(dbp, NULL, "complex.db", NULL, DB_HASH, flags, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; init_DBT(&amp;key, &amp;data);<br><br>&nbsp; key.size = sizeof(int);<br>&nbsp; key.data = &amp;(cust.c_id);<br><br>&nbsp; data.size = sizeof(CUSTOMER);<br>&nbsp; data.data = &amp;cust;<br><br>&nbsp; ret = dbp-&gt;put(dbp, NULL, &amp;key, &amp;data,DB_NOOVERWRITE);<br>&nbsp; print_error(ret);<br><br>&nbsp; memset(&amp;cust, 0, sizeof(CUSTOMER));<br><br>&nbsp; key.size = sizeof(int);<br>&nbsp; key.data = &amp;key_cust_c_id;<br><br>&nbsp; data.data = &amp;cust;<br>&nbsp; data.ulen = sizeof(CUSTOMER);<br>&nbsp; data.flags = DB_DBT_USERMEM;<br><br>&nbsp; dbp-&gt;get(dbp, NULL, &amp;key, &amp;data, 0);<br>&nbsp; print_error(ret);<br><br>&nbsp; printf("c_id = %d name = %s address = %s age = %d\n",<br>&nbsp;&nbsp;&nbsp; &nbsp; cust.c_id, cust.name, cust.address, cust.age);<br><br>&nbsp; if(dbp != NULL)<br>&nbsp;&nbsp;&nbsp; dbp-&gt;close(dbp, 0);<br>&nbsp; return 0;<br>}</span></p><p><span >运行.test.out:</span></p><p><span >ERROR: DB_KEYEXIST: Key/data pair already exists<br>The number = 15<br>ERROR: DB_KEYEXIST: Key/data pair already exists<br>ERROR: DB_KEYEXIST: Key/data pair already exists<br>c_id = 1 name = javer address = chengdu age = 32<br>说明安装成功：以后研究：</span></p><p><span >然后安装libevent：</span></p><p><span >cd libevent:</span></p><pre>[root@localhost]#cd libevent-1.2<br>[root@localhost]#./configure --prefix=/opt/libevent &amp;&amp; make &amp;&amp; make install</pre><p><span >安装成功后，安装crawl</span></p><p><span >参数为：</span></p><pre> ./configure --prefix=/opt/crall  --with-libevent=/usr/<br>checking build system type... i686-pc-linux-gnu<br>checking host system type... i686-pc-linux-gnu<br>checking target system type... i686-pc-linux-gnu<br>checking for a BSD-compatible install... /usr/bin/install -c<br>checking whether build environment is sane... yes<br>checking whether make sets ${MAKE}... yes<br>checking for working aclocal-1.4... missing<br>checking for working autoconf... missing<br>checking for working automake-1.4... missing<br>checking for working autoheader... missing<br>checking for working makeinfo... missing<br>checking for gcc... gcc<br>checking for C compiler default output... a.out<br>checking whether the C compiler works... yes<br>checking whether we are cross compiling... no<br>checking for suffix of executables... <br>checking for suffix of object files... o<br>checking whether we are using the GNU C compiler... yes<br>checking whether gcc accepts -g... yes<br>checking for gcc option to accept ANSI C... none needed<br>checking for a BSD-compatible install... /usr/bin/install -c<br>checking if we may use "-I/usr/include"... no<br>checking for libevent... /usr/<br>configure: error: event.h or libevent.a not found in /usr/<br><br></pre>而且已经把libevent-1.4.so.2 copy到/usr/lib<br>为什么不可以呢？<br> </div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/1396854820096212441212</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/1396854820096212441212</guid>
    <pubDate>Thu, 2 Jul 2009 01:24:41 +0800</pubDate>
    <dcterms:modified>2009-07-02T01:24:41+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[数码摄影技巧]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952710493451</link>
    <description><![CDATA[<div>&nbsp;今日看了看《跟我学数码摄影》，里面还是有些东西值得学习的，豆瓣的地址：http://www.douban.com/subject/3208677。<br>记录下他们介绍的原则：<br>摄影构图的基本原则<br>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></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952710493451</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952710493451</guid>
    <pubDate>Sat, 27 Jun 2009 10:49:34 +0800</pubDate>
    <dcterms:modified>2009-06-27T10:49:34+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[awk使用找到mysql结果的数据]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952665056907</link>
    <description><![CDATA[<div>mysql选择出的数据格式为：<br>*************************** 1. row ***************************<br>url_id: 1#386808#267#雕刻时光推荐好声音（第二场）—台湾组合乐队专场<br>*************************** 2. row ***************************<br>url_id: 1#387113#267#感恩父亲节专场演唱会温馨谢幕~<br>找出相应的uid的shell<br>sed '/\*/d' topiclist.txt |awk -F '#' 'BEGIN{ORS=","}{print $2}'|sort|uniq|sed 's/.$//'</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952665056907</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952665056907</guid>
    <pubDate>Fri, 26 Jun 2009 18:50:56 +0800</pubDate>
    <dcterms:modified>2009-06-26T18:50:56+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[数据库永久连接mysql_pconnect和mysql_connect]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952554133438</link>
    <description><![CDATA[<div>&nbsp;&nbsp;&nbsp; 一直对mysql_pconnect 和mysql_connect的理解差别是p链接是持久链接，不会关闭了链接，即使你使用了mysql_close();建立连接后，将保持sleep状态，可以使用show processlist 查看有哪些正在sleep的连接，这样p链接的好处是当有新的请求时就直接返回这个连接，感觉类似于http1.1协议的keep-alive的用法，到底是开个还是关呢还是不关呢，一般那些专家都告诉你，当用户量不多时，可以打开keep -live 这样可以，在http协议进行打交道时，给用户保持连接。用户第一次打开建立，然后继续浏览时就不需要新开了，提高用户的体验，当用户量比较大的时候，大量的保持连接会给服务器造成很大压力，所以需要找一个平衡点是开到底还是不开，回过头来看mysql_p 的理解：&nbsp;&nbsp;&nbsp; 在网上搜索了没有找到满意的答案，但是在竟然在手册上看到一个解释的比较完美的，看来以后应该多看手册：<br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">定义：</span><br>&nbsp;&nbsp;&nbsp; 永久的数据库连接是指在脚本结束运行时不关闭的连接。当收到一个永久连接的请求时。PHP 将检查是否已经存在一个（前面已经开启的）相同的永久连接。如果存在，将直接使用这个连接；如果不存在，则建立一个新的连接。所谓“相同”的连接是指用相同的用户名和密码到相同主机的连接。 <br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">先看看手册上的总结：</span><br>&nbsp;&nbsp;&nbsp; 永久连接是为通常连接建立一对一的分布而设计的。这意味着必须能够保证在将永久连接替换为非永久连接时，脚本的行为不会改变。使用永久连接将（非常）有可能改变脚本的效率，但不改变其行为！ <br><span style="font-weight: bold;">&nbsp;&nbsp;&nbsp; 如果永久连接并没有任何附加的功能，那么使用它有什么好处？ </span><br>&nbsp;&nbsp;&nbsp; 答案非常简单――效率。当客户端对 SQL 服务器的连接请求非常频繁时，永久连接将更加高效。连接请求频繁的标准取决于很多因素。例如，数据库的种类，数据库服务和 web 服务是否在同一台服务器上，SQL 服务器如何加载负载等。但我们至少知道，当连接请求很频繁时，永久连接将显著的提高效率。<span style="color: rgb(255, 0, 0); font-weight: bold;">它使得每个子进程在其生命周期中只做一次连接操作，而非每次在处理一个页面时都要向 SQL 服务器提出连接请求。这也就是说，每个子进程将对服务器建立各自独立的永久连接。</span>例如，如果有 20 个不同的子进程运行某脚本建立了永久的 SQL 服务器永久连接，那么实际上向该 SQL 服务器建立了 20 个不同的永久连接，每个进程占有一个。<br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">注意</span>，如果永久连接的子进程数目超过了设定的数据库连接数限制，系统将会产生一些缺陷。如果数据库的同时连接数限制为 16，而在繁忙会话的情况下，有 17 个线程试图连接，那么有一个线程将无法连接。如果这个时候，在脚本中出现了使得连接无法关闭的错误（例如无限循环），则该数据库的 16 个连接将迅速地受到影响。请查阅使用的数据库的文档，以获取关于如何处理已放弃的及闲置的连接的方法。 <br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">警告</span>：在使用永久连接时还有一些特别的问题需要注意。例如在永久连接中使用数据表锁时，如果脚本不管什么原因无法释放该数据表锁，其随后使用相同连接的脚本将会被永久的阻塞，使得需要重新启动 httpd 服务或者数据库服务。另外，在使用事务处理时，如果脚本在事务阻塞产生前结束，则该阻塞也会影响到使用相同连接的下一个脚本。不管在什么情况下，都可以通过使用 register_shutdown_function() 函数来注册一个简单的清理函数来打开数据表锁，或者回滚事务。或者更好的处理方法，是不在使用数据表锁或者事务处理的脚本中使用永久连接，这可以从根本上解决这个问题（当然还可以在其它地方使用永久连接）。 <br><br><br><span style="font-weight: bold;">&nbsp;web 服务器可以用三种方法来利用 PHP 生成 web 页面。 </span><br><br>&nbsp;第一种方法是将 PHP 用作一个“外壳”。以这种方法运行，PHP 会为向 web 服务器提出的每个 PHP 页面请求生成并结束一个 PHP 解释器线程。由于该线程会随每个请求的结束而结束，因此任何在这个线程中利用的任何资源（例如指向 SQL 数据库服务器的连接）都会随线程的结束而关闭。在这种情况下，使用永久连接不会获得任何地改变――因为它们根本不是永久的。 <br><br>第二，也是最常用的方法，是把 PHP 用作多进程 web 服务器的一个模块，这种方法目前只适用于 Apache。对于一个多进程的服务器，其典型特征是有一个父进程和一组子进程协调运行，其中实际生成 web 页面的是子进程。每当客户端向父进程提出请求时，该请求会被传递给还没有被其它的客户端请求占用的子进程。这也就是说当相同的客户端第二次向服务端提出请求时，它将有可能被一个不同的子进程来处理。在开启了一个永久连接后，所有请求 SQL 服务的后继页面都能够重新使用这个已经建立的 SQL Server 连接。 <br><br>最后一种方法是将 PHP 用作多线程 web 服务器的一个插件。目前 PHP 4 已经支持 ISAPI、WSAPI 和 NSAPI（在 Windows 环境下），这些使得 PHP 可以被用作诸如 Netscape FastTrack (iPlanet)、Microsoft's Internet Information Server (IIS) 和 O'Reilly's WebSite Pro 等多线程 web 服务器的插件。永久连接的行为和前面所描述的多过程模型在本质上是相同的。注意 PHP 3 不支持 SAPI。 <br><br><br><br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952554133438</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952554133438</guid>
    <pubDate>Thu, 25 Jun 2009 17:41:33 +0800</pubDate>
    <dcterms:modified>2009-06-27T10:53:38+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[ssh tar 合作处理网络文件]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952461957462</link>
    <description><![CDATA[<div>传输文件有时候考ryscn完成，但是有一些功能可以通过tar和ssh完成<br>先看一句 ：<br>sed "s%^$BASEDIR/$module_name/%%" $listOP |<br>ssh $REMOTE_USER@$remote_host "mkdir -p $bpath $REMOTE_PATH; tar -C $REMOTE_PATH -jcf $bpath/$tarball.$VER_TODAY$remove_suffix -T - $remove_args";<br>这句就是别人写的一个应用：<br>然后我发现了一些：<br>tar和find结合的：<br><br>find / -type f -print | grep -iE '\.doc$' | tar -czvf test.tar.gz<br>find . -mount -depth -type f -print | grep -iE '*\.txt$' | tar -czvf ../test.tar.gz <br>继续一些别的命令学习：<br>ssh myname@boxname 'cd /logs; tar cf - $(find . -name "*.Z")' |tar xf - <br>(cd /bkup02/ieee/fulltext/2007; tar cf - $(find . -name xml.zip) ) | ssh user@xxx.xxx.xxx.xxx"tar -C /opt/backup/ieee/2007 -xf -"<br>user@xxx.xxx.xxx.xxx's password:<br>tar cf - files | ssh surtr "(cd /home/joe/tmp; tar xf -)"<br>$ ssh surtr "(cd /home/joe/tmp; tar cvjf /home/joe/pkgs.tar.bz2 pkgs)" \<br>&amp;&amp; scp surtr:~/pkgs.tar.bz2<br>学会了这些我们来个终极版：<br>地址在：<br>&nbsp;&nbsp; &nbsp;http://ultra.ap.krakow.pl/~bar/DOC/ssh_backup.html<br><br>PUSH 将本地文件到远程服务器:<br><br>&nbsp;&nbsp;&nbsp; * tar cvf - . | gzip -c -1 | ssh user@host cat "&gt;" remotefile.gz<br>&nbsp;&nbsp;&nbsp; * ssh target_address cat &lt;localfile "&gt;" remotefile<br>&nbsp;&nbsp;&nbsp; * ssh target_address cat &lt;localfile - "&gt;" remotefile<br>&nbsp;&nbsp;&nbsp; * cat localfile | ssh target_address cat "&gt;" remotefile<br>&nbsp;&nbsp;&nbsp; * cat localfile | ssh target_address cat - "&gt;" remotefile<br>&nbsp;&nbsp;&nbsp; * dd if=localfile | ssh target_address dd of=remotefile<br>&nbsp;&nbsp;&nbsp; * ssh target_address cat &lt;localfile "|" dd of=remotefile<br>&nbsp;&nbsp;&nbsp; * ssh target_address cat - &lt;localfile "|" dd of=remotefile<br>&nbsp;&nbsp;&nbsp; * ( cd SOURCEDIR &amp;&amp; tar cf - . ) | ssh target_address "(cd DESTDIR &amp;&amp; tar xvpf - )"<br>&nbsp;&nbsp;&nbsp; * ( cd SOURCEDIR &amp;&amp; tar cvf - . ) | ssh target_address "(cd DESTDIR &amp;&amp; cat - &gt; remotefile.tar )"<br>&nbsp;&nbsp;&nbsp; * ( cd SOURCEDIR &amp;&amp; tar czvf - . ) | ssh target_address "(cd DESTDIR &amp;&amp; cat - &gt; remotefile.tgz )"<br>&nbsp;&nbsp;&nbsp; * ( cd SOURCEDIR &amp;&amp; tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR &amp;&amp; cat - &gt; remotefile.tgz )"<br>&nbsp;&nbsp;&nbsp; * ssh target_address "( nc -l -p 9210 &gt; remotefile &amp; )" &amp;&amp; cat source-file | gzip -1 - | nc target_address 9210<br>&nbsp;&nbsp;&nbsp; * cat localfile | gzip -1 - | ssh target_address cat "&gt;" remotefile.gz<br><br><br>PULL:把远程文件从远程弄到本地<br>&nbsp;&nbsp; &nbsp;# ssh target_address cat remotefile &gt; localfile<br>&nbsp;&nbsp; &nbsp;# ssh target_address dd if=remotefile | dd of=localfile<br>&nbsp;&nbsp; &nbsp;# ssh target_address cat "&lt;" remotefile &gt;localfile<br>&nbsp;&nbsp; &nbsp;# ssh target_address cat "&lt;" remotefile.gz | gunzip &gt;localfile<br><br>COMPARE:<br>&nbsp;&nbsp; &nbsp;# ###This on<wbr>e uses CPU cycles on the remote server to compare the files:<br>&nbsp;&nbsp; &nbsp;# ssh target_address cat remotefile | diff - localfile<br>&nbsp;&nbsp; &nbsp;# cat localfile | ssh target_address diff - remotefile<br>&nbsp;&nbsp; &nbsp;# ###This on<wbr>e uses CPU cycles on the local server to compare the files:<br>&nbsp;&nbsp; &nbsp;# ssh target_address cat &lt;localfile "|" diff - remotefile<br>本地文件的一些操作<br>复制<br>&nbsp;&nbsp;&nbsp; * ( cd SOURCEDIR &amp;&amp; tar cf - . ) | (cd DESTDIR &amp;&amp; tar xvpf - )<br><br>FTP VIEW:<br><br>&nbsp;&nbsp;&nbsp; * ftp&gt; get file.gif "| xv -"<br>&nbsp;&nbsp;&nbsp; * ftp&gt; get README "| more"<br><br>FTP PUSH:<br><br>&nbsp;&nbsp;&nbsp; * ftp&gt; put "| tar cvf - ." myfile.tar<br>&nbsp;&nbsp;&nbsp; * ftp&gt; put "| tar cvf - . | gzip " myfile.tar.gz<br><br>FTP PULL:<br><br>&nbsp;&nbsp;&nbsp; * ftp&gt; get myfile.tar "| tar xvf -"<br><br>Pipes and Redirects:<br><br>&nbsp;&nbsp;&nbsp; * zcat Fig.ps.Z | gv -<br>&nbsp;&nbsp;&nbsp; * gunzip -c Fig.ps.gz | gv -<br>&nbsp;&nbsp;&nbsp; * tar xvf mydir.tar<br>&nbsp;&nbsp;&nbsp; * tar xvf - &lt; mydir.tar<br>&nbsp;&nbsp;&nbsp; * cat mydir.tar | tar xvf -<br>&nbsp;&nbsp;&nbsp; * tar cvf mydir.tar .<br>&nbsp;&nbsp;&nbsp; * tar cvf - . &gt; mydir.tar<br>&nbsp;&nbsp;&nbsp; * tar cf - . | (cd ~/newdir; tar xf -)<br>&nbsp;&nbsp;&nbsp; * gunzip -c foo.gz &gt; bar<br>&nbsp;&nbsp;&nbsp; * cat foo.gz | gunzip &gt; bar<br>&nbsp;&nbsp;&nbsp; * zcat foo.gz &gt; bar<br>&nbsp;&nbsp;&nbsp; * gzip -c foo &gt; bar.gz<br>&nbsp;&nbsp;&nbsp; * cat foo | gzip &gt; bar.gz<br>&nbsp;&nbsp;&nbsp; * cat foo | gzip &gt; bar.gz<br>相信你能学会很多从这里<br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952461957462</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952461957462</guid>
    <pubDate>Wed, 24 Jun 2009 18:19:57 +0800</pubDate>
    <dcterms:modified>2009-06-24T18:27:17+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[统计php.err里的错误]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952321556950</link>
    <description><![CDATA[<div><style></style><div><font size="2">如题：<br><br>awk -F "]" '{if(NF&gt;=3){print $3} else{print $2}}' php.err 
|sort|uniq|sed -e 's/^:/ /'|awk '{print NR,$0}' &gt;on<wbr>ly.err<br><br><br>删除掉script里的文本：<br></font><div  &nbsp;&nbsp;style="font-family:Fixdays" id="code0">:%s#\(&lt;script contentType="application/x-javas<wbr>cript"&gt;\)[^&lt;]*\(&lt;/script&gt;\)#\1\2#</div><font size="2">同事学习了下awk里的循环：<br><span style="color: rgb(0, 0, 0); font-weight: bold;">（摘抄）</span><br></font>awk条件语句<br><br>条件语句<br><br>awk中的条件语句是从C语言中借鉴过来的，可控制程序的流程。<br>14.5.1. if语句<br><br>格式：<br>{if (expression){<br>statement; statement; ...<br>}<br>}<br><br>$ awk '{if ($1 &lt;$2) print $2 "too high"}' test。如果第一个域小于第二个域则打印。<br><br>$ awk '{if ($1 &lt; $2) {count++; print "ok"}}' test.如果第一个域小于第二个域，则count加一，并打印ok。<br>14.5.2. if/else语句，用于双重判断。<br><br>格式：<br>{if (expression){<br>statement; statement; ...<br>}<br>else{<br>statement; statement; ...<br>}<br>}<br><br>$ awk '{if ($1 &gt; 100) print $1 "bad" ; else print "ok"}' test。如果$1大于100则打印$1 bad,否则打印ok。<br><br>$ awk '{if ($1 &gt; 100){ count++; print $1} else {count--; print $2}' test。如果$1大于100，则count加一，并打印$1，否则count减一，并打印$1。<br>14.5.3. if/else else if语句，用于多重判断。<br><br>格式：<br>{if (expression){<br>statement; statement; ...<br>}<br>else if (expression){<br>statement; statement; ...<br>}<br>else if (expression){<br>statement; statement; ...<br>}<br>else {<br>statement; statement; ...<br>}<br>}<br><br>14.6. 循环<br><br>*<br><br>awk有三种循环:while循环；for循环；special for循环。<br>*<br><br>$ awk '{ i = 1; while ( i &lt;= NF ) { print NF,$i; i++}}' test。变量的初始值为1，若i小于可等于NF(记录中域的个数),则执行打印语句，且i增加1。直到i的值大于NF.<br>*<br><br>$ awk '{for (i = 1; i *<br><br>breadkcontinue语句。break用于在满足条件的情况下跳出循环；continue用于在满足条件的情况下忽略后面的语句，直接返回循环的顶端。如：<br><br>{for ( x=3; x&lt;=NF; x++) <br>if ($x&lt;0){print "Bottomed out!"; break}}<br>{for ( x=3; x&lt;=NF; x++)<br>if ($x==0){print "Get next item"; continue}}<br><br><br>*<br><br>next语句从输入文件中读取一行，然后从头开始执行awk脚本。如：<br><br>{if ($1 ~/test/){next}<br>else {print}<br>}<br><br><br>*<br><br>exit语句用于结束awk程序，但不会略过END块。退出状态为0代表成功，非零值表示出错。<br><br>14.7. 数组<br><br>awk中的数组的下标可以是数字和字母，称为关联数组。<br>14.7.1. 下标与关联数组<br><br>*<br><br>用变量作为数组下标。如：$ awk {name[x++]=$2};END{for(i=0;i *<br><br>special for循环用于读取关联数组中的元素。格式如下：<br><br>{for (item in arrayname){<br>print arrayname[item]<br>}<br>}<br><br>$ awk '/^tom/{name[NR]=$1}; END{for(i in name){print name[i]}}' test。打印有值的数组元素。打印的顺序是随机的。<br>*<br><br>用字符串作为下标。如：count["test"]<br>*<br><br>用
域值作为数组的下标。一种新的for循环方式，for (index_value in array) statement。如:$ awk
'{count[$1]++} END{for(name in count) print name,count[name]}'
test。该语句将打印$1中字符串出现的次数。它首先以第一个域作数组count的下标，第一个域变化，索引就变化。<br>*<br><br>delete
函数用于删除数组元素。如：$ awk '{line[x++]=$1} END{for(x in line) delete(line[x])}'
test。分配给数组line的是第一个域的值，所有记录处理完成后，special for循环将删除每一个元素。<br><font size="2"><br></font></div></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952321556950</comments>
    <slash:comments>2</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952321556950</guid>
    <pubDate>Tue, 23 Jun 2009 14:15:56 +0800</pubDate>
    <dcterms:modified>2009-06-23T16:26:52+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[Crucial Concepts Behind Advanced Regular Expressions(转)]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200952011585455</link>
    <description><![CDATA[<div><p><br></p><p>转：http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/<br></p><p>Regular expressions (or regex) are a powerful way to traverse large
strings in order to find information. They rely on underlying patterns
in a string’s structure to work their magic. Unfortunately, simple
regular expressions are unable to cope with complex patterns and
symbols. To deal with this dilemma, you can use <strong>advanced regular expressions</strong>.</p>
<p>Below, we present an <strong>introduction to advanced regular expressions</strong>,
with eight commonly used concepts and examples. Each example outlines a
simple way to match patterns in complex strings. If you do not yet have
experience with basic regular expressions, have a look at <a href="http://www.lateralcode.com/regular-expressions/">this article</a> to get started. The syntax used here matches PHP’s Perl-compatible regular expressions.</p>
<h3>1. Greediness/Laziness</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" original="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/greed.jpg" src="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/greed.jpg" alt="Greed" height="300" width="400"></p>
<p>All regex repetition operators are <strong>greedy</strong>. They try
to match as much as possible in a string. Unfortunately, this might not
always be a desired effect. Thus, lazy operators are used to solve this
problem. They only match the smallest possible pattern and are used by
adding a ‘?’ after the respective greedy operator. Alternatively, the
‘U’ modifier may be used to make all repetiton operators lazy.
Differentiating between greediness and laziness is key to fully
understanding advanced regular expressions.</p>
<h4>Greedy Operators</h4>
<p>The * operator matches the previous expression 0 or more times. It is a greedy operator. Consider the following expression:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>preg_match(&nbsp;</span><span >'/&lt;h1&gt;.*&lt;\/h1&gt;/'</span><span>,&nbsp;'&lt;h1&gt;This&nbsp;is&nbsp;a&nbsp;heading.&lt;/h1&gt;&nbsp;&nbsp;</span></span></li><li ><span>&lt;h1&gt;This&nbsp;is&nbsp;another&nbsp;one.&lt;/h1&gt;',&nbsp;<span >$matches</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >preg_match( '/&lt;h1&gt;.*&lt;\/h1&gt;/', '&lt;h1&gt;This is a heading.&lt;/h1&gt;
&lt;h1&gt;This is another one.&lt;/h1&gt;', $matches );</pre>

<p>Recall that a . means any character except a new line. The above
regular expression is looking for an h1 tag and all of its contents. It
uses the . and * operators to constantly match anything inside the tag.
This pattern will match:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>&lt;h1&gt;This&nbsp;is&nbsp;a&nbsp;heading.&lt;/h1&gt;&lt;h1&gt;This&nbsp;is&nbsp;another&nbsp;one.&lt;/h1&gt;&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >&lt;h1&gt;This is a heading.&lt;/h1&gt;&lt;h1&gt;This is another one.&lt;/h1&gt;</pre>

<p>It returns the whole string. The * operator will continuously match
everything — even the middle closing h1 tag — because it is greedy.
Matching the whole string is the best it can do.</p>
<h4>Lazy Operators</h4>
<p>Let’s change the above operator by adding a ‘?’ after it. This will make it lazy:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/&lt;h1&gt;.*?&lt;\/h1&gt;/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/&lt;h1&gt;.*?&lt;\/h1&gt;/</pre>

<p>The regex now fulfills its duty and matches only the first h1 tag.
Another greedy operator that uses this same property is {n,}. This
matches the previous expression n or more times. If it is used without
a question mark, it looks for the most repetitions possible. Otherwise,
it starts from n repetitions:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span >#&nbsp;Set&nbsp;up&nbsp;a&nbsp;String</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >$str</span><span>&nbsp;=&nbsp;</span><span >'hihi'</span><span>;&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;Match&nbsp;it&nbsp;using&nbsp;the&nbsp;greedy&nbsp;{n,}&nbsp;operator</span><span>&nbsp;&nbsp;</span></span></li><li ><span>preg_match(&nbsp;<span >'/(hi){1,}/'</span><span>,&nbsp;</span><span >$str</span><span>,&nbsp;</span><span >$matches</span><span>&nbsp;);&nbsp;</span><span >#&nbsp;matches[0]&nbsp;will&nbsp;be&nbsp;'hihi'</span><span>&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;Match&nbsp;it&nbsp;with&nbsp;the&nbsp;lazy&nbsp;{n,}?&nbsp;operator</span><span>&nbsp;&nbsp;</span></span></li><li ><span>preg_match(&nbsp;<span >'/(hi){1,}?/'</span><span>,&nbsp;</span><span >$str</span><span>,&nbsp;</span><span >$matches</span><span>&nbsp;);&nbsp;</span><span >#&nbsp;matches[0]&nbsp;will&nbsp;be&nbsp;'hi'</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  ># Set up a String
$str = 'hihi';

# Match it using the greedy {n,} operator
preg_match( '/(hi){1,}/', $str, $matches ); # matches[0] will be 'hihi'

# Match it with the lazy {n,}? operator
preg_match( '/(hi){1,}?/', $str, $matches ); # matches[0] will be 'hi'</pre>

<h3>2. Back Referencing</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/back.jpg" src="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/back.jpg" alt="Back Referencing" height="290" width="300"></p>
<h4>What it does</h4>
<p><strong>Back referencing</strong> is a way to refer to previously
matched patterns inside a regular expression. For example, take a look
at this simple regex that matches an expression in quotes:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span >#&nbsp;Set&nbsp;up&nbsp;an&nbsp;array&nbsp;of&nbsp;matches</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >$matches</span><span>&nbsp;=&nbsp;</span><span >array</span><span>();&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;Create&nbsp;a&nbsp;String</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >$str</span><span>&nbsp;=&nbsp;</span><span >"\"This&nbsp;is&nbsp;a&nbsp;'string'\""</span><span>;&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;Traverse&nbsp;it&nbsp;with&nbsp;regular&nbsp;expressions</span><span>&nbsp;&nbsp;</span></span></li><li ><span>preg_match(&nbsp;<span >"/(\"|').*?(\"|')/"</span><span>,&nbsp;</span><span >$str</span><span>,&nbsp;</span><span >$matches</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;Print&nbsp;the&nbsp;whole&nbsp;match</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >echo</span><span>&nbsp;&nbsp;</span><span >$matches</span><span>[0];&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  ># Set up an array of matches
$matches = array();

# Create a String
$str = "\"This is a 'string'\"";

# Traverse it with regular expressions
preg_match( "/(\"|').*?(\"|')/", $str, $matches );

# Print the whole match
echo  $matches[0];</pre>

<p>Unfortunately, this will not correctly match the string. Instead, it will print:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>"This&nbsp;is&nbsp;a&nbsp;'&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >"This is a '</pre>

<p>This regular expression matches the opening double quote but finds a
different type of quote to close it. This is because it was given the
option of picking a double or single quote at the end. In order to fix
this, you can use back referencing. The <strong>expressions \1, \2, ….,  \9</strong> hold references to previously captured subpatterns. The first matched quote, in this case, will be held by the variable \1.</p>
<h4>How to Use It</h4>
<p>In order to apply this concept to the aforementioned example, use \1 in place of the last quote:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>preg_match(&nbsp;</span><span >'/("|\').*?\1/'</span><span>,&nbsp;</span><span >$str</span><span>,&nbsp;</span><span >$matches</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >preg_match( '/("|\').*?\1/', $str, $matches );</pre>

<p>This will now correctly return:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span >"This&nbsp;is&nbsp;a&nbsp;'string'"</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >"This is a 'string'"</pre>

<p>Remember that back referencing may also be used by <code>preg_replace</code>.
Note that instead of \1 … \9, you should use $1 … $9 … $n (any number
of these will work). For example, if you want to replace all paragraph
tags with text that represents them, use:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span >$text</span><span>&nbsp;=&nbsp;preg_replace(&nbsp;</span><span >'/&lt;p&gt;(.*?)&lt;\/p&gt;/'</span><span>,&nbsp;&nbsp;</span></span></li><li ><span><span >"&amp;lt;p&amp;gt;$1&amp;lt;/p&amp;gt;"</span><span>,&nbsp;</span><span >$html</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >$text = preg_replace( '/&lt;p&gt;(.*?)&lt;\/p&gt;/',
"&amp;lt;p&amp;gt;$1&amp;lt;/p&amp;gt;", $html );</pre>

<p>The $1 back reference holds the text inside the paragraph and is
being used in the replace pattern itself. This completely valid
expression shows an easy way to access matched patterns even while
replacing.</p>
<h3>3. Named Groups</h3>
<p>When using multiple back references, a regular expression can
quickly become confusing and hard to understand. An alternative way to
back reference is by using <strong>named groups</strong>. A named group is specified by using <code>(?P&lt;name&gt;pattern)</code>,
where name is the name of the group and pattern is the regular
expression in the group itself. The group can then be referred to by
(?P=name). For example, consider the following:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/(?P&lt;quote&gt;"|').*?(?P=quote)/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/(?P&lt;quote&gt;"|').*?(?P=quote)/</pre>

<p>The above expression will create the same effect as the previous
back reference example, but by instead using named groups. It is also
significantly easier to read.</p>
<p>Named groups are also useful when sifting through the array of
matches. The name given to a specific pattern is also the key of the
corresponding matches array.</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>preg_match(&nbsp;</span><span >'/(?P&lt;quote&gt;"|\')/'</span><span>,&nbsp;"</span><span >'String'</span><span>",&nbsp;</span><span >$matches</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;This&nbsp;will&nbsp;print&nbsp;"'"</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >echo</span><span>&nbsp;</span><span >$matches</span><span>[1];&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;</span></li><li ><span><span >#&nbsp;This&nbsp;will&nbsp;also&nbsp;print&nbsp;"'",&nbsp;as&nbsp;it&nbsp;is&nbsp;a&nbsp;named&nbsp;group</span><span>&nbsp;&nbsp;</span></span></li><li ><span><span >echo</span><span>&nbsp;</span><span >$matches</span><span>[</span><span >'quote'</span><span>];&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >preg_match( '/(?P&lt;quote&gt;"|\')/', "'String'", $matches );

# This will print "'"
echo $matches[1];

# This will also print "'", as it is a named group
echo $matches['quote'];</pre>

<p>Thus, named groups not only make code easier to read but also organize it.</p>
<h3>4. Word Boundaries</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/boundary.jpg" src="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/boundary.jpg" alt="Word Boundaries" height="284" width="400"></p>
<p><strong>Word boundaries</strong> are places in a string that come
between a word character and a non-word character. The specialty of
these boundaries is the fact that they don’t actually match a
character. Their length is <em>zero</em>. The <code>\b</code> regular expression matches any word boundary.</p>
<p>Unfortunately, boundaries are so often skimmed over that many do not
recognize their real significance. For example, let’s say you want to
match the word “import”:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/import/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/import/</pre>

<p>Watch out! Regular expressions can be tricky. The above expression will also match:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>important&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >important</pre>

<p>You may think it is as simple as adding a space before and after import to prevent these bogus matches:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/&nbsp;import&nbsp;/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/ import /</pre>

<p>But what about this case?</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>The&nbsp;trader&nbsp;voted&nbsp;</span><span >for</span><span>&nbsp;the&nbsp;import&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >The trader voted for the import</pre>

<p>When import is at the beginning or the end of a string, the modified
regex will fail. Thus, splitting this up into cases is required:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/(^import&nbsp;|&nbsp;import&nbsp;|&nbsp;import$)/i&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/(^import | import | import$)/i</pre>

<p>Looking back at our regular expression, it does not take periods or
other punctuation into account. Just to match this single word, a
regular expressions may look like this:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/(^import(:|;|,)?&nbsp;|&nbsp;import(:|;|,)?&nbsp;|&nbsp;import(\.|\?|!)?$)/i&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/(^import(:|;|,)? | import(:|;|,)? | import(\.|\?|!)?$)/i</pre>
<p>That’s a lot of code to match just a single word. This is why word
boundaries are so significant. To accomplish the above statement and <strong>many other variations</strong> with word boundaries, all that is necessary is:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\bimport\b/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\bimport\b/</pre>

<p>This will match every case above and more. <code>\b</code>’s
flexibility comes from the fact that it matches a zero-length string.
All it matches is an imaginary space between two characters. It checks
if one of the characters is a non-word character and the other is a
word character. If so, it matches it. If the beginning or end of a
string is encountered, <code>\b</code> treats it as a non-word character. Because the <code>i</code> in import is still considered a word character, it will match import.</p>
<p>Note that the opposite of \b is \B. This operator will match the
space in-between two word or two non-word characters. Thus, if you
would like to match ‘hi’ inside another word, you could use:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>\Bhi\B&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >\Bhi\B</pre>

<h3>5. Atomic Groups</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/groups.jpg" src="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/groups.jpg" alt="Advanced Operators" height="266" width="400"></p>
<p><strong>Atomic groups</strong> are special regex groups that are
non-capturing. They are usually used to increase the efficiency of a
regular expression, but may also be applied to eliminate certain
matches. An atomic group is specified by using (?&gt;pattern):</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/(?&gt;his|this)/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/(?&gt;his|this)/</pre>

<p>When the regex engine matches an atomic group, it will discard
backtracting positions that came with all tokens inside it. Consider
the word ’smashing’. Using the above regular expression, the regex
engine will first try to match the pattern ‘his’ in ’smashing’. It will
not find a match. At this point, the atomic group will kick in. The
engine will discard all backtracking positions. This means that it will
not search for ‘this’ inside ’smashing’. Why? If ‘his’ did not return a
match, then obviously ‘this’ (which includes ‘his’) will not return
positive either.</p>
<p>The above example did not have many practical uses. We might as well have used <code>/t?his?/</code> instead. Look at the following:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\b(engineer|engrave|</span><span >end</span><span>)\b/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\b(engineer|engrave|end)\b/</pre>

<p>If the regex engine is given the word ‘engineering’, it will
correctly match ‘engineer’. The next word boundary, \b, will not match.
Thus, it will move on to the next match: engrave. It realizes that the
‘eng’ matches, but the rest do not. Finally, ‘end’ is attempted and
also failed. If you look carefully, you will realize that once the
engine matches ‘engineer’ and fails the last word boundary, it can not
possibly match ‘engrave’ or ‘end’. These two matches are smaller words
than ‘engineer’, and thus the regex engine should not continue with the
other trials.</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\b(?&gt;engineer|engrave|</span><span >end</span><span>)\b/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\b(?&gt;engineer|engrave|end)\b/</pre>

<p>The above is a much better alternative that will save the regex engine time and improve the code’s efficiency.</p>
<h3>6. Recursion</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/recursion.jpg" src="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/recursion.jpg" alt="Recursion" height="300" width="400"></p>
<p><strong>Recursion</strong> in regular expressions can be used to match nested constructs, such as parentheses, (this (that)), and HTML tags, <code>&lt;div&gt;&lt;/div&gt;</code>. They require the use of <code>(?R)</code>, an operator that matches recursive sub-patterns. Consider the regular expression that matches nested parentheses:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\(((?&gt;[^()]+)|(?R))*\)/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\(((?&gt;[^()]+)|(?R))*\)/</pre>

<p>The outermost parentheses in this regular expression match the
beginning of the nested constructs. Then comes an optional operator,
which can either match non-parenthetical characters (<code>?&gt;[^()]+</code>)
or the whole expression again in a sub-pattern, (?R). Notice that this
operator is repeated as many times as possible to match all nested
parentheses.</p>
<p>Another example of recursion at work is the following:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/&lt;([\w]+).*?&gt;((?&gt;[^&lt;&gt;]+)|((?R)))*&lt;\/\1&gt;/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/&lt;([\w]+).*?&gt;((?&gt;[^&lt;&gt;]+)|((?R)))*&lt;\/\1&gt;/</pre>
<p>The above expression combines character groups, greedy operators,
back-tracking, and atomic groups to match nested tags. The first
parenthesized group ([\w]+) matches the tag name for use later in the
regular expression. It then proceeds to match the rest of the tag. The
next parenthesized sub-expression is very similar to the one above. It
either matches non-tag (?&gt;[^&lt;&gt;]+) characters or recurses over
another tag (?R). Finally, the last part of the expression matches the
close tag.</p>
<h3>7. Callbacks</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/call.jpg" src="http://media2.smashingmagazine.com/images/advanced-regular-expressions-php/call.jpg" alt="Callbacks" height="290" width="400"></p>
<p>Certain matches in a pattern may require special modifications. In order to apply multiple or complex changes, <strong>callbacks</strong> can be used. A callback is used for dynamic substitution Strings in the <code>preg_replace_callback</code>
function. They take in a function as a parameter to use when a match is
found. This function receives the match array as a parameter and
returns a modified string that is used as a replacement.</p>
<p>As an example, consider a regular expression that changes all words
to uppercase in a given string. Unfortunately, PHP does not have a
regex operator that changes a character to a different case. To
accomplish this task, a callback may be used. First, the expression
must match all letters that need to be capitalized:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\b\w/&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\b\w/</pre>

<p>The above uses both word boundaries and character classes to work.
Now that we have this expression, we can write a callback function:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span >function</span><span>&nbsp;upper_case(&nbsp;</span><span >$matches</span><span>&nbsp;)&nbsp;{&nbsp;&nbsp;</span></span></li><li ><span>&nbsp;&nbsp;&nbsp;&nbsp;<span >return</span><span>&nbsp;</span><span >strtoupper</span><span>(&nbsp;</span><span >$matches</span><span>[0]&nbsp;);&nbsp;&nbsp;</span></span></li><li ><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;"  >function upper_case( $matches ) {
 return strtoupper( $matches[0] );
}</pre>

<p><code>upper_case</code> takes in an array of matches and returns the whole matched pattern in uppercase. <code>$matches[0]</code>, in this case, represents the letter that needs to be capitalized. All of this can now be put together using the <code>preg_replace_callback</code> function:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>preg_replace_callback(&nbsp;</span><span >'/\b\w/'</span><span>,&nbsp;</span><span >"upper_case"</span><span>,&nbsp;</span><span >$str</span><span>&nbsp;);&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >preg_replace_callback( '/\b\w/', "upper_case", $str );</pre>

<p>That is the power of a simple callback.</p>
<h3>8. Commenting</h3>
<p><img title="Crucial Concepts Behind Advanced Regular Expressions(转) -  小和尚 - 小和尚真情无限" style="display: inline;" original="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/comment.jpg" src="http://media1.smashingmagazine.com/images/advanced-regular-expressions-php/comment.jpg" alt="Commenting" height="300" width="400"></p>
<p><strong>Commenting</strong> is not a way to actually match strings,
but it is one of the most important parts of regular expressions. As
you dive deep into larger, more complex expressions, it becomes hard to
decipher what is actually being matched. Using comments in the middle
of regular expressions is the perfect way to minimize such confusion.</p>
<p>To place a comment inside a regular expression, use the <code>(?#comment)</code> format. Replace “comment” with the word(s) of your choice:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/(?</span><span >#digit)\d/</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/(?#digit)\d/</pre>

<p>It is especially important to comment regular expressions that you
release to the public. Users of your regex will be able to easily
understand and modify the pattern to meet their needs. It can even go
so far as to help you decode it when revisiting a program.</p>
<p>Consider using the “x” or (?x) modifier for free-spacing mode with
comments. This causes a regular expression to ignore white space
between tokens. All spaces can still be represented with <code>[ ]</code> or <code>\ </code> (a backslash and a space):</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/&nbsp;&nbsp;</span></span></li><li ><span>\d&nbsp;&nbsp;&nbsp;&nbsp;<span >#digit</span><span>&nbsp;&nbsp;</span></span></li><li ><span>[&nbsp;]&nbsp;&nbsp;&nbsp;<span >#space</span><span>&nbsp;&nbsp;</span></span></li><li ><span>\w+&nbsp;&nbsp;&nbsp;<span >#word</span><span>&nbsp;&nbsp;</span></span></li><li ><span>/x&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;"  >/
\d    #digit
[ ]   #space
\w+   #word
/x</pre>

<p>The above is the same as:</p>
<div ><div ><div ><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >view plain</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >copy to clipboard</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >print</a><a href="http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/#" >?</a></div></div><ol ><li ><span><span>/\d(?</span><span >#digit)[&nbsp;](?#space)\w+(?#word)/</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;"  >/\d(?#digit)[ ](?#space)\w+(?#word)/</pre>

<p>Always create well-documented code.</p>
<h3>Further Resources</h3>
<ul><li><a href="http://www.regular-expressions.info/">Regular-Expressions.info</a><br>Comprehensive website on regular expressions</li><li><a href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/">Cheat Sheet</a><br>Informative regular expressions cheat sheet</li><li><a href="http://www.jslab.dk/tools.regex.php">Regex Generator</a><br>JavaScript regular expressions generator</li></ul>
<h4>About the author</h4><em>Karthik Viswanathan is a high-school student who loves to program and create websites. You can view Karthik’s work on his blog, <a href="http://www.lateralcode.com/">Lateral Code</a>, and explore the most popular articles on the Web through his online <a href="http://twitter.lateralcode.com/">Twitter application</a>.</em><br><br></div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200952011585455</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200952011585455</guid>
    <pubDate>Sat, 20 Jun 2009 11:58:05 +0800</pubDate>
    <dcterms:modified>2009-06-20T11:58:05+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[dd奇技淫巧]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/139685482009518201234</link>
    <description><![CDATA[<div><p>在cu上看到一个帖子：http://bbs2.chinaunix.net/viewthread.php?tid=1469980&amp;extra=&amp;page=1</p><p>
<span style="font-size: 16px; color: rgb(0, 0, 0);">
 
<b>怎样对一个大文件的某个字节进行直接修改</b></span></p><div>比如我想把一个很大的视频文件中的第i个字节的值改成0x41（也就是大写字母A的ASCII值），<br>
不用C的话，有没有现成的工具可以用啊？<br>实现：
echo A | dd of=bigfile seek=$i bs=1 count=1 conv=notrunc<br>股沟之：<br></div>
<p><br></p><p>一、dd命令的解释。</p>
<p>dd：用指定大小的块拷贝一个文件，并在拷贝的同时进行指定的转换。</p>
<p>注意：指定数字的地方若以下列字符结尾则乘以相应的数字：b=512；c=1；k=1024；w=2</p>
<p>参数：</p>
<p>1. if=文件名：输入文件名，缺省为标准输入。即指定源文件。&lt; if=input file &gt;</p>
<p>2. of=文件名：输出文件名，缺省为标准输出。即指定目的文件。&lt; of=output file &gt;</p>
<p>3. ibs=bytes：一次读入bytes个字节，即指定一个块大小为bytes个字节。</p>
<p>&nbsp;&nbsp;&nbsp; obs=bytes：一次输出bytes个字节，即指定一个块大小为bytes个字节。</p>
<p>&nbsp;&nbsp;&nbsp; bs=bytes：同时设置读入/输出的块大小为bytes个字节。</p>
<p>4. cbs=bytes：一次转换bytes个字节，即指定转换缓冲区大小。</p>
<p>5. skip=blocks：从输入文件开头跳过blocks个块后再开始复制。</p>
<p>6. seek=blocks：从输出文件开头跳过blocks个块后再开始复制。</p>
<p>注意：通常只用当输出文件是磁盘或磁带时才有效，即备份到磁盘或磁带时才有效。</p>
<p>7. count=blocks：仅拷贝blocks个块，块大小等于ibs指定的字节数。</p>
<p>8. conv=conversion：用指定的参数转换文件。</p>
<p>&nbsp;&nbsp;&nbsp; ascii：转换ebcdic为ascii</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; ebcdic：转换ascii为ebcdic</p>
<p>&nbsp;&nbsp;&nbsp; ibm：转换ascii为alternate ebcdic</p>
<p>&nbsp;&nbsp;&nbsp; block：把每一行转换为长度为cbs，不足部分用空格填充</p>
<p>&nbsp;&nbsp;&nbsp; unblock：使每一行的长度都为cbs，不足部分用空格填充</p>
<p>&nbsp;&nbsp;&nbsp; lcase：把大写字符转换为小写字符</p>
<p>&nbsp;&nbsp;&nbsp; ucase：把小写字符转换为大写字符</p>
<p>&nbsp;&nbsp;&nbsp; swab：交换输入的每对字节</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; noerror：出错时不停止</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; notrunc：不截短输出文件</p>
<p>&nbsp;&nbsp;&nbsp; sync：将每个输入块填充到ibs个字节，不足部分用空（NUL）字符补齐。</p>
<p>二、dd应用实例。</p>
<p>1.将本地的/dev/hdb整盘备份到/dev/hdd</p>
<p>&nbsp;&nbsp; dd if=/dev/hdb of=/dev/hdd</p>
<p>2.将/dev/hdb全盘数据备份到指定路径的image文件</p>
<p>&nbsp;&nbsp; dd if=/dev/hdb of=/root/image</p>
<p>3.将备份文件恢复到指定盘</p>
<p>&nbsp;&nbsp; dd if=/root/image of=/dev/hdb</p>
<p>4.备份/dev/hdb全盘数据，并利用gzip工具进行压缩，保存到指定路径</p>
<p>&nbsp;&nbsp;&nbsp; dd if=/dev/hdb | gzip &gt; /root/image.gz</p>
<p>5.将压缩的备份文件恢复到指定盘</p>
<p>&nbsp;&nbsp; gzip -dc /root/image.gz | dd of=/dev/hdb</p>
<p>6.备份磁盘开始的512个字节大小的MBR信息到指定文件</p>
<p>&nbsp;&nbsp; dd if=/dev/hda of=/root/image count=1 bs=512</p>
<p>&nbsp;&nbsp; count=1指<span style="color: rgb(255, 0, 255);">仅拷贝一个块</span>；bs=512指<span style="color: rgb(255, 0, 255);">块大小为512个字节</span>。</p>
<p>&nbsp;&nbsp; 恢复：dd if=/root/image of=/dev/hda</p>
<p>7.备份软盘</p>
<p>&nbsp;&nbsp; dd if=/dev/fd0 of=disk.img count=1 bs=1440k (即块大小为1.44M)</p>
<p>8.拷贝内存内容到硬盘</p>
<p>&nbsp;&nbsp; dd if=/dev/mem of=/root/mem.bin bs=1024 (指定块大小为1k)&nbsp;&nbsp;</p>
<p>9.拷贝光盘内容到指定文件夹，并保存为cd.iso文件</p>
<p>&nbsp;&nbsp; dd if=/dev/cdrom(hdc) of=/root/cd.iso</p>
<p>10.增加swap分区文件大小</p>
<p>第一步：创建一个大小为256M的文件：</p>
<p><span style="color: rgb(255, 0, 0);">dd if=/dev/zero of=/swapfile bs=1024 count=262144</span></p>
<p>第二步：把这个文件变成swap文件：</p>
<p><span style="color: rgb(255, 0, 0);">mkswap /swapfile</span></p>
<p>第三步：启用这个swap文件：</p>
<p><span style="color: rgb(255, 0, 0);">swapon /swapfile</span></p>
<p>第四步：编辑/etc/fstab文件，使在每次开机时自动加载swap文件：</p>
<p><span style="color: rgb(255, 0, 0);">/swapfile&nbsp;&nbsp;&nbsp; swap&nbsp;&nbsp;&nbsp; swap&nbsp;&nbsp;&nbsp; default&nbsp;&nbsp; 0 0</span></p>
<p>11.销毁磁盘数据</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/urandom of=/dev/hda1</p>
<p>注意：<span style="color: rgb(255, 0, 0);">利用随机的数据填充硬盘</span>，在某些必要的场合可以用来销毁数据。</p>
<p>12.测试硬盘的读写速度</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dd if=/root/1Gb.file bs=64k | dd of=/dev/null</p>
<p>通过以上两个命令输出的命令执行时间，可以计算出硬盘的读、写速度。</p>
<p>13.确定硬盘的最佳块大小：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file</p>
<p>通过比较以上命令输出中所显示的<span style="color: rgb(255, 0, 255);">命令执行时间</span>，即可确定系统最佳的块大小。</p>
<p>14.修复硬盘：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; dd if=/dev/sda of=/dev/sda 或dd if=/dev/hda of=/dev/hda</p>
<p>当硬盘较长时间(一年以上)放置不使用后，磁盘上会产生magnetic flux
point，当磁头读到这些区域时会遇到困难，并可能导致I/O错误。当这种情况影响到硬盘的第一个扇区时，可能导致硬盘报废。上边的命令有可能使这些数
据起死回生。并且这个过程是安全、高效的。</p>



<div><span style="color: rgb(255, 102, 0);"><strong>/dev/null和/dev/zero的区别</strong></span></div>
<div><span style="color: rgb(255, 102, 0);"><strong></strong></span></div>
/dev/null，外号叫无底洞，你可以向它输出任何数据，它通吃，并且不会撑着！<br>/dev/zero,是一个输入设备，你可你用它来初始化文件。

<p>/dev/null，外号叫无底洞，你可以向它输出任何数据，它通吃，并且不会撑着！<br>/dev/zero,是一个输入设备，你可你用它来初始化文件。</p>

<div>/dev/null------它是空设备，也称为位桶（bit bucket）。任何写入它的输出都会被抛弃。如果不想让消息以标准输出显示或写入文件，那么可以将消息重定向到位桶。<br>/dev/zero------该设备无穷尽地提供0，可以使用任何你需要的数目——设备提供的要多的多。他可以用于向设备或文件写入字符串0。</div>
<p>oracle@localhost oracle]$if=/dev/zero of=./test.txt bs=1k count=1<br>oracle@localhost oracle]$ ls -l<br>total 4<br>-rw-r--r--&nbsp; &nbsp; 1 oracle&nbsp; &nbsp;dba&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 1024 Jul 15 16:56 test.txt</p>

<p>eg,<br><br>&nbsp; &nbsp; find / -name access_log&nbsp;&nbsp;2&gt;/dev/null</p>



<p>使用/dev/null <br>把/dev/null看作"黑洞". 它非常等价于一个只写文件. 所有写入它的内容都会永远丢失. 而尝试从它那儿读取内容则什么也读不到. 然而, /dev/null对命令行和脚本都非常的有用.</p>
<p>禁止标准输出.&nbsp;&nbsp;&nbsp; 1 cat $filename &gt;/dev/null<br>&nbsp;&nbsp; 2 # 文件内容丢失，而不会输出到标准输出.<br>&nbsp;</p>
<p><br>禁止标准错误 (来自例子 12-3).&nbsp;&nbsp;&nbsp; 1 rm $badname 2&gt;/dev/null<br>&nbsp;&nbsp; 2 #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样错误信息[标准错误]就被丢到太平洋去了.<br>&nbsp;</p>
<p><br>禁止标准输出和标准错误的输出.&nbsp;&nbsp;&nbsp; 1 cat $filename 2&gt;/dev/null &gt;/dev/null<br>&nbsp;&nbsp; 2 # 如果"$filename"不存在，将不会有任何错误信息提示.<br>&nbsp;&nbsp; 3 # 如果"$filename"存在, 文件的内容不会打印到标准输出.<br>&nbsp;&nbsp; 4 # 因此Therefore, 上面的代码根本不会输出任何信息.<br>&nbsp;&nbsp; 5 #<br>&nbsp;&nbsp; 6 #&nbsp; 当只想测试命令的退出码而不想有任何输出时非常有用。<br>&nbsp;&nbsp; 7 #<br>&nbsp;&nbsp; 8 #<br>&nbsp;&nbsp; 9 # cat $filename &amp;&gt;/dev/null<br>&nbsp; 10 #&nbsp;&nbsp;&nbsp;&nbsp; 也可以, 由 Baris Cicek 指出.<br>&nbsp;</p>
<p><br>Deleting contents of a file, but preserving the file itself,
with all attendant permissions (from Example 2-1 and Example 2-3):&nbsp;&nbsp;&nbsp; 1
cat /dev/null &gt; /var/log/messages<br>&nbsp;&nbsp; 2 #&nbsp; : &gt; /var/log/messages&nbsp;&nbsp; 有同样的效果, 但不会产生新的进程.（因为:是内建的）<br>&nbsp;&nbsp; 3 <br>&nbsp;&nbsp; 4 cat /dev/null &gt; /var/log/wtmp<br>&nbsp;</p>
<p><br>自动清空日志文件的内容 (特别适合处理这些由商业Web站点发送的讨厌的"cookies"):</p>
<p><br>--------------------------------------------------------------------------------</p>
<p>例子 28-1. 隐藏cookie而不再使用</p>
<p>&nbsp;&nbsp; 1 if [ -f ~/.netscape/cookies ]&nbsp; # 如果存在则删除.<br>&nbsp;&nbsp; 2 then<br>&nbsp;&nbsp; 3&nbsp;&nbsp; rm -f ~/.netscape/cookies<br>&nbsp;&nbsp; 4 fi<br>&nbsp;&nbsp; 5 <br>&nbsp;&nbsp; 6 ln -s /dev/null ~/.netscape/cookies<br>&nbsp;&nbsp; 7 # 现在所有的cookies都会丢入黑洞而不会保存在磁盘上了.<br>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>使用/dev/zero <br>像/dev/null一样, /dev/zero也是一个伪文件,
但它实际上产生连续不断的null的流（二进制的零流，而不是ASCII型的）. 写入它的输出会丢失不见,
而从/dev/zero读出一连串的null也比较困难, 虽然这也能通过od或一个十六进制编辑器来做到.
/dev/zero主要的用处是用来创建一个指定长度用于初始化的空文件，就像临时交换文件.</p>
<p><br>--------------------------------------------------------------------------------</p>
<p>例子 28-2. 用/dev/zero创建一个交换临时文件</p>
<p>&nbsp;&nbsp; 1 #!/bin/bash<br>&nbsp;&nbsp; 2 # 创建一个交换文件.<br>&nbsp;&nbsp; 3 <br>&nbsp;&nbsp; 4 ROOT_UID=0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Root 用户的 $UID 是 0.<br>&nbsp;&nbsp; 5 E_WRONG_USER=65&nbsp;&nbsp;&nbsp; # 不是 root?<br>&nbsp;&nbsp; 6 <br>&nbsp;&nbsp; 7 FILE=/swap<br>&nbsp;&nbsp; 8 BLOCKSIZE=1024<br>&nbsp;&nbsp; 9 MINBLOCKS=40<br>&nbsp; 10 SUCCESS=0<br>&nbsp; 11 <br>&nbsp; 12 <br>&nbsp; 13 # 这个脚本必须用root来运行.<br>&nbsp; 14 if [ "$UID" -ne "$ROOT_UID" ]<br>&nbsp; 15 then<br>&nbsp; 16&nbsp;&nbsp; echo; echo "You must be root to run this script."; echo<br>&nbsp; 17&nbsp;&nbsp; exit $E_WRONG_USER<br>&nbsp; 18 fi&nbsp; <br>&nbsp; 19&nbsp;&nbsp; <br>&nbsp; 20 <br>&nbsp; 21 blocks=${1:-$MINBLOCKS}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; 如果命令行没有指定，<br>&nbsp; 22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #+ 则设置为默认的40块.<br>&nbsp; 23 # 上面这句等同如：<br>&nbsp; 24 # --------------------------------------------------<br>&nbsp; 25 # if [ -n "$1" ]<br>&nbsp; 26 # then<br>&nbsp; 27 #&nbsp;&nbsp; blocks=$1<br>&nbsp; 28 # else<br>&nbsp; 29 #&nbsp;&nbsp; blocks=$MINBLOCKS<br>&nbsp; 30 # fi<br>&nbsp; 31 # --------------------------------------------------<br>&nbsp; 32 <br>&nbsp; 33 <br>&nbsp; 34 if [ "$blocks" -lt $MINBLOCKS ]<br>&nbsp; 35 then<br>&nbsp; 36&nbsp;&nbsp; blocks=$MINBLOCKS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 最少要有 40 个块长.<br>&nbsp; 37 fi&nbsp; <br>&nbsp; 38 <br>&nbsp; 39 <br>&nbsp; 40 echo "Creating swap file of size $blocks blocks (KB)."<br>&nbsp; 41 dd if=/dev/zero of=$FILE bs=$BLOCKSIZE count=$blocks&nbsp; # 把零写入文件.<br>&nbsp; 42 <br>&nbsp; 43 mkswap $FILE $blocks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 将此文件建为交换文件（或称交换分区）.<br>&nbsp; 44 swapon $FILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 激活交换文件.<br>&nbsp; 45 <br>&nbsp; 46 echo "Swap file created and activated."<br>&nbsp; 47 <br>&nbsp; 48 exit $SUCCESS<br>&nbsp;</p>
<p>--------------------------------------------------------------------------------</p>
<p>关于 /dev/zero 的另一个应用是为特定的目的而用零去填充一个指定大小的文件, 如挂载一个文件系统到环回设备 （loopback device） (参考例子 13-8) 或"安全地" 删除一个文件(参考例子 12-55).</p>
<p><br>--------------------------------------------------------------------------------</p>
<p>例子 28-3. 创建ramdisk</p>
&nbsp;&nbsp; 1 #!/bin/bash<br>&nbsp;&nbsp; 2 # ramdisk.sh<br>&nbsp;&nbsp; 3 <br>&nbsp;&nbsp; 4 #&nbsp; "ramdisk"是系统RAM内存的一段，<br>&nbsp;&nbsp; 5 #+ 它可以被当成是一个文件系统来操作.<br>&nbsp;&nbsp; 6 #&nbsp; 它的优点是存取速度非常快 (包括读和写).<br>&nbsp;&nbsp; 7 #&nbsp; 缺点: 易失性, 当计算机重启或关机时会丢失数据.<br>&nbsp;&nbsp; 8 #+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 会减少系统可用的RAM.<br>&nbsp;&nbsp; 9 #<br>&nbsp; 10 #&nbsp; 那么ramdisk有什么作用呢?<br>&nbsp; 11 #&nbsp; 保存一个较大的数据集在ramdisk, 比如一张表或字典,<br>&nbsp; 12 #+ 这样可以加速数据查询, 因为在内存里查找比在磁盘里查找快得多.<br>&nbsp; 13 <br>&nbsp; 14 <br>&nbsp; 15 E_NON_ROOT_USER=70&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 必须用root来运行.<br>&nbsp; 16 ROOTUSER_NAME=root<br>&nbsp; 17 <br>&nbsp; 18 MOUNTPT=/mnt/ramdisk<br>&nbsp; 19 SIZE=2000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 2K 个块 (可以合适的做修改)<br>&nbsp; 20 BLOCKSIZE=1024&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 每块有1K (1024 byte) 的大小<br>&nbsp; 21 DEVICE=/dev/ram0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 第一个 ram 设备<br>&nbsp; 22 <br>&nbsp; 23 username=`id -nu`<br>&nbsp; 24 if [ "$username" != "$ROOTUSER_NAME" ]<br>&nbsp; 25 then<br>&nbsp; 26&nbsp;&nbsp; echo "Must be root to run \"`basename $0`\"."<br>&nbsp; 27&nbsp;&nbsp; exit $E_NON_ROOT_USER<br>&nbsp; 28 fi<br>&nbsp; 29 <br>&nbsp; 30 if [ ! -d "$MOUNTPT" ]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; 测试挂载点是否已经存在了,<br>&nbsp; 31 then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #+ 如果这个脚本已经运行了好几次了就不会再建这个目录了<br>&nbsp; 32&nbsp;&nbsp; mkdir $MOUNTPT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #+ 因为前面已经建立了.<br>&nbsp; 33 fi<br>&nbsp; 34 <br>&nbsp; 35 dd if=/dev/zero of=$DEVICE count=$SIZE bs=$BLOCKSIZE&nbsp; # 把RAM设备的内容用零填充.<br>&nbsp; 36&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 为何需要这么做?<br>&nbsp; 37 mke2fs $DEVICE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 在RAM设备上创建一个ext2文件系统.<br>&nbsp; 38 mount $DEVICE $MOUNTPT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 挂载设备.<br>&nbsp; 39 chmod 777 $MOUNTPT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 使普通用户也可以存取这个ramdisk.<br>&nbsp; 40&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 但是, 只能由root来缷载它.<br>&nbsp; 41 <br>&nbsp; 42 echo "\"$MOUNTPT\" now available for use."<br>&nbsp; 43 # 现在 ramdisk 即使普通用户也可以用来存取文件了.<br>&nbsp; 44 <br>&nbsp; 45 #&nbsp; 注意, ramdisk是易失的, 所以当计算机系统重启或关机时ramdisk里的内容会消失.<br>&nbsp; 46 #<br>&nbsp; 47 #&nbsp; 拷贝所有你想保存文件到一个常规的磁盘目录下.<br>&nbsp; 48 <br>&nbsp; 49 # 重启之后, 运行这个脚本再次建立起一个 ramdisk.<br>&nbsp; 50 # 仅重新加载 /mnt/ramdisk 而没有其他的步骤将不会正确工作.<br>&nbsp; 51 <br>&nbsp; 52 #&nbsp; 如果加以改进, 这个脚本可以放在 /etc/rc.d/rc.local,<br>&nbsp; 53 #+ 以使系统启动时能自动设立一个ramdisk.<br>&nbsp; 54 #&nbsp; 这样很合适速度要求高的数据库服务器.<br>&nbsp; 55 <br>&nbsp; 56 exit 0<br><br><br>这样，一些诸如一些错误信息就不会显示出来</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/139685482009518201234</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/139685482009518201234</guid>
    <pubDate>Thu, 18 Jun 2009 14:00:01 +0800</pubDate>
    <dcterms:modified>2009-06-18T14:00:45+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[ 如何优化你的php（二）]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/139685482009426113210323</link>
    <description><![CDATA[<div><style>
<!--    @font-face  {font-family:宋体;  panose-1:2 1 6 0 3 1 1 1 1 1;  mso-font-alt:SimSun;  mso-font-charset:134;  mso-generic-font-family:auto;  mso-font-pitch:variable;  mso-font-signature:3 135135232 16 0 262145 0;} @font-face  {font-family:"@宋体";  panose-1:2 1 6 0 3 1 1 1 1 1;  mso-font-charset:134;  mso-generic-font-family:auto;  mso-font-pitch:variable;  mso-font-signature:3 135135232 16 0 262145 0;}    p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-parent:"";  margin:0cm;  margin-bottom:.0001pt;  text-align:justify;  text-justify:inter-ideograph;  mso-pagination:none;  font-size:10.5pt;  mso-bidi-font-size:12.0pt;  font-family:"Times New Roman";  mso-fareast-font-family:宋体;  mso-font-kerning:1.0pt;} p  {mso-margin-top-alt:auto;  margin-right:0cm;  mso-margin-bottom-alt:auto;  margin-left:0cm;  mso-pagination:widow-orphan;  font-size:12.0pt;  font-family:宋体;  mso-bidi-font-family:宋体;}    @page  {mso-page-border-surround-header:no;  mso-page-border-surround-footer:no;} @page Section1  {size:612.0pt 792.0pt;  margin:72.0pt 90.0pt 72.0pt 90.0pt;  mso-header-margin:36.0pt;  mso-footer-margin:36.0pt;  mso-paper-source:0;} div.Section1  {page:Section1;} -->
-->--></style>

<p><span style="font-size: 10.5pt;">翻译：http://phplens.com/lens/php-book/optimizing-debugging-php.php</span></p><p><span style="font-size: 10.5pt;">今天翻译着翻译着，已经烦了，看来真的持之以恒做一件事很难，尤其是不太喜欢的事情，我略过和跳过，和翻译错了很多。<br></span></p><p><span style="font-size: 10.5pt;">为<span lang="EN-US">php</span>调试你的<span lang="EN-US">web</span>服务器<span lang="EN-US"></span></span></p>

<p style="text-indent: 21pt;"><span style="font-size: 10.5pt;">我们将论述在今天两种非常常用的<span lang="EN-US">web</span>服务器如何得到最好的性能，<span lang="EN-US">apache1.2</span>和<span lang="EN-US">iis</span>，当然也有许多关于服务<span lang="EN-US">html</span>的建议。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 10.5pt;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp; </span>Php</span><span style="font-size: 10.5pt;">的作者表示<span lang="EN-US">apache2.0</span>相对于<span lang="EN-US">apache1.3</span>没有性能和架构的优点，特别是多线程模式，但<span lang="EN-US">apache2.0</span>以预分配模式运行的时候，下面的讨论依然有关系（<span lang="EN-US">2003</span>年<span lang="EN-US">11 21</span>）<span lang="EN-US"></span></span></p>

<p style="text-indent: 21pt;"><span style="font-size: 10.5pt;">（<span lang="EN-US">a
apache1.3/2.0</span></span></p>

<p><span style="font-size: 10.5pt;" lang="EN-US">apache</span><span style="font-size: 10.5pt;">可以运行在<span lang="EN-US">unix</span>和<span lang="EN-US">windows</span>上面，它是当今世界最流行的服务器，<span lang="EN-US">apache1.3</span>在服务器运行时用了预分配模式，但它启动时，它会创建多个子进程来处理<span lang="EN-US">http</span>请求，初始化的父进程间就像一个呵护天使，确保每个子进程工作地顺利同时协调所有的事情，越多的<span lang="EN-US">http</span>请求过来，越多的子进程出来处理它们，但<span lang="EN-US">http</span>请求慢下来的时候，父进程会杀死一个空闲的进程，为别的进程释放资源，这个模式使得<span lang="EN-US">apache</span>非常的健壮，即使一个子进程崩溃了，父进程和别的进程是和这个崩溃的进程独立的。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 10.5pt;">预分配模式不像别的设计的那么快，但对我来说，服务一个<span lang="EN-US">php</span>脚本足够了，当<span lang="EN-US">apache</span>性能组织非常重大的影响前还有很多别的瓶颈要找。<span lang="EN-US">Apache</span>的健壮性和信赖性非常重要。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 10.5pt;" lang="EN-US">Apace2.0</span><span style="font-size: 10.5pt;">提供了在执行时采用多线程模式，我的测试表明在这种模式下只有一点性能上的优点。当然好多<span lang="EN-US">php</span>的扩展部兼容。<span lang="EN-US">Apache2.0.47</span>（<span lang="EN-US">2003</span>）。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 10.5pt;" lang="EN-US">Apache</span><span style="font-size: 10.5pt;">的配置使用<span lang="EN-US">httpd.conf</span>，下面的参数在配置子进程的时候非常重要。<span lang="EN-US"></span></span></p>

<table style="width: 486.75pt;" width="649" border="1" cellpadding="0" cellspacing="1">
 <tbody><tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">命令</span></b><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">默认</span></b><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">描述</span></b><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MaxClients</span><span style="font-size: 7.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">256 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">最大的子进程的数量，默认的意思是最多同时处理</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">256</span><span style="font-size: 12pt; font-family: 宋体;">个</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-size: 12pt; font-family: 宋体;">请求，多的连接被放在队列里。</span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">StartServers</span><span style="font-size: 7.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">5 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">启动时候创建的子进程个数</span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MinSpareServers</span><span style="font-size: 7.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">5 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">需要创建的空闲子进程的数目，如果子进程的数目低于这个数字，</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">1</span><span style="font-size: 12pt; font-family: 宋体;">个子进程被初始化创建，然后是</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">2</span><span style="font-size: 12pt; font-family: 宋体;">个，后来是</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">4</span><span style="font-size: 12pt; font-family: 宋体;">个，直到</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">32</span><span style="font-size: 12pt; font-family: 宋体;">个被创建每秒钟</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MaxSpareServers</span><span style="font-size: 7.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">10 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">如果激活的子进程多于这个数字，多的进程将被中止掉</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 21%;" valign="top" width="21%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MaxRequestsPerChild
  </span><span style="font-size: 7.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 13%;" valign="top" width="13%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 65%;" valign="top" width="65%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">子进程中止前能处理的</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-size: 12pt; font-family: 宋体;">请求数</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">.</span><span style="font-size: 12pt; font-family: 宋体;">设置成</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0 </span><span style="font-size: 12pt; font-family: 宋体;">表示永远不终止</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">.</span><span style="font-size: 12pt; font-family: 宋体;">设置为</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">100</span><span style="font-size: 12pt; font-family: 宋体;">到</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">10000</span><span style="font-size: 12pt; font-family: 宋体;">如果你怀疑有内存泄漏，或者来释放一些没有用的资源</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">. </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
</tbody></table>

<p><span style="font-size: 10.5pt;">如果是大一点的网站，值设置成下面的会好一点：<span lang="EN-US"></span></span></p>

<p><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MinSpareServers
32 </span></p>

<p><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">MaxSpareServers
64</span></p>

<p><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">Apache</span><span style="font-size: 10.5pt;">在</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">windows</span><span style="font-size: 10.5pt;">有点不一样，它不是用子进程，而是用线程，上面的参数将不会用到，相比我们有一个参数：</span><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">ThreadsPerChild</span></i><i><span style="font-size: 10.5pt;">，默认的是</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">50</span></i><i><span style="font-size: 10.5pt;">，这个参数表示</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">apache</span></i><i><span style="font-size: 10.5pt;">可以多少个线程交换</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">.</span></i><i><span style="font-size: 10.5pt;">在</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">windows</span></i><i><span style="font-size: 10.5pt;">的版主中只有一个子进程，默认的设置成</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">50<span style="">&nbsp;&nbsp; </span></span></i><i><span style="font-size: 10.5pt;">当前只可以处理</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">50</span></i><i><span style="font-size: 10.5pt;">个请求。但</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">web</span></i><i><span style="font-size: 10.5pt;">服务器经历高的网络流量时，增加它在</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">256</span></i><i><span style="font-size: 10.5pt;">和</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">1024</span></i><i><span style="font-size: 10.5pt;">之间，一些有用的参数你可以改变，包括如下：</span></i><i><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></i></p>

<table style="width: 465.75pt;" width="621" border="1" cellpadding="0" cellspacing="1">
 <tbody><tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">参数</span></b><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">默认</span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: 宋体;">描述</span></b><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">SendBufferSize </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">设置成操作系统默认的</span><span style="font-family: &quot;Courier New&quot;;"> </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">决定在用</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">tcp/ip</span><span style="font-family: 宋体;">连接时候用到的输出的缓冲大小。对于忙的网络是非常有用的当你缓存时候，你可以设置这个参数关闭最大的文件下载。每个客户端连接的时候</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">tcp/ip</span><span style="font-family: 宋体;">缓冲都会创建。</span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">KeepAlive [on|off]</span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">On </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">在老的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-family: 宋体;">协议中，每个</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-family: 宋体;">请求都需要在服务器上单独建立个连接。为了减少过多的正常连接，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">keep-live</span><span style="font-family: 宋体;">的头被发展开了，它告诉服务器继续使用同一个</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">socket</span><span style="font-family: 宋体;">处理多个请求，如果一个独立的专为突破服务器的服务器，你可以关闭这个选项，这个技术很大的提高了资源的可用性</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">. </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">KeepAliveTimeout </span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">15 </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">这个数字式保持</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">socket</span><span style="font-family: 宋体;">连接的存活时间，这个时间包括服务器生成内容，和客户机响应，如果客户机不响应，他将生成一个新连接。这个值得将保持低值做为</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">socket</span><span style="font-family: 宋体;">扩展时代的空闲</span><span style="font-family: &quot;Courier New&quot;;"> </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">MaxKeepAliveRequests </span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">100 </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">当它设置的值达到的时候</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">socket</span><span style="font-family: 宋体;">的连接将会被终止，保持这个高数字，在</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">maxclients</span><span style="font-family: 宋体;">和</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">threadsperchild</span><span style="font-family: 宋体;">之间</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">TimeOut </span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">300 </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">当空闲时间超出这个断开连接</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">.</span><span style="font-family: 宋体;">但你的用户很少的时候你可以设置的很低</span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 33.5%;" valign="top" width="33%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">LimitRequestBody </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 19.74%;" valign="top" width="19%">
  <p style="text-align: left;" align="left"><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">0 </span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 46.16%;" valign="top" width="46%">
  <p style="text-align: left;" align="left"><span style="font-family: 宋体;">最大的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">post</span><span style="font-family: 宋体;">或者</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">get</span><span style="font-family: 宋体;">的值</span><span style="font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
</tbody></table>

<p><span style="font-size: 10.5pt;">如果你不需要</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">dns</span><span style="font-size: 10.5pt;">轮询同时你不需要</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">httaccess</span><span style="font-size: 10.5pt;">文件配置你的</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">apache</span><span style="font-size: 10.5pt;">设置你可以设置的私人的目录：</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"># </span><span style="font-size: 9pt;">禁用</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">dns</span><span style="font-size: 9pt;">轮询</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">php</span><span style="font-size: 9pt;">脚本只得到</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">ip</span><span style="font-size: 9pt;">地址</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp; </span></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">HostnameLookups
<b>off </b></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"># </span><span style="font-size: 9pt;">关闭</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">htaccess</span><span style="font-size: 9pt;">的检查</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">&lt;Directory
/&gt; </span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">AllowOverride
<b>none </b></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">&lt;/Directory&gt;
</span></p>

<p><span style="font-size: 9pt;">但有符号链接的时候，如果你不担心路径的安全，打开</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">FollowSymLinks</span><span style="font-size: 9pt;">，关闭</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">SymLinksIfOwnerMatch</span><span style="font-size: 9pt;">，防止多余的</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">lstat</span><span style="font-size: 9pt;">系统调用，当创造的时候。</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">Options
FollowSymLinks </span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">#Options
SymLinksIfOwnerMatch</span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">(b iis </span><span style="font-size: 9pt;">的调试：</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt;">跳过</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt;">在</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">windows</span><span style="font-size: 9pt;">下的高性能：</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">iis</span><span style="font-size: 9pt;">和</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">fastcgi<br>
</span><span style="font-size: 9pt;">通过多次测试，我发现在</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">windows</span><span style="font-size: 9pt;">下最好的性能是</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">iis</span><span style="font-size: 9pt;">用</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">fastcgi</span><span style="font-size: 9pt;">方式，</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">cgi</span><span style="font-size: 9pt;">是个协议为服务器调用其他程序，它不快，因为每次页面请求完后，他就中止了，</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">fastcgi</span><span style="font-size: 9pt;">为了高性能，修改了这个协议，使得每个页面请求完，</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">cgi</span><span style="font-size: 9pt;">程序永久的，当心的页面过来时重新使用这个程序。</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US">Php4<span style="font-family: 宋体;" lang="EN-US"><span lang="EN-US">’</span></span>s
zend engine</span></p>

<p><span style="font-size: 9pt;">简略的：工作模式如下：</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p style="text-align: center;" align="center"><a href="http://img.bimg.126.net/photo/3dDlIi5Q7uLRYjR1cuzrLQ==/3994692869478332889.jpg" target="_blank"><img title=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" alt=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/3dDlIi5Q7uLRYjR1cuzrLQ==/3994692869478332889.jpg"></a></p>

<p><span lang="EN-US">Php</span>脚本被<span lang="EN-US">zend engine</span>加载，编译到<span lang="EN-US">zend opcode</span>，执行代码的缩写代码，低级的二进制指令，<span lang="EN-US">opcode</span>被执行后，生成<span lang="EN-US">html</span>发送到客户端。执行时<span lang="EN-US">opcode</span>将被在内存中刷新。</p>

<p><span style="font-size: 9pt;">今天有多种产品和技术帮助你加速这个进程，下图我们展现<span lang="EN-US">php</span>脚本的工作方式，每个方框都是功能。<span lang="EN-US"></span></span></p>

<p style="text-align: center;" align="center"><a href="http://img.bimg.126.net/photo/JaMNqyqYPj0XsP57Xmixpw==/5644980657932805833.jpg" target="_blank"><img title=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" alt=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/JaMNqyqYPj0XsP57Xmixpw==/5644980657932805833.jpg"></a></p><p style="text-align: center;" align="center"><br></p><p style="text-align: center;" align="center">中间能加缓存的就加吧，如<br></p><p><font size="3"><strong>一、eAccelerator</strong></font></p><p><font size="3"><strong>二、APC</strong></font></p><p><font size="3"><strong>三、XCache</strong></font></p><p><font size="+2" face="helvetica,verdana,sans-serif"><b><font size="3">四 PHP Accelerator</font></b></font></p><p><font size="+2" face="helvetica,verdana,sans-serif"><b><font size="3">提供如下几个图</font></b></font></p><p><a href="http://img.bimg.126.net/photo/Wayn_nJ0XHTxK4i5dlbrCw==/2845712014545310968.jpg" target="_blank"><img title=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" alt=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/Wayn_nJ0XHTxK4i5dlbrCw==/2845712014545310968.jpg"></a><a href="http://img.bimg.126.net/photo/JbwR88iow09HgKt4JqN77g==/2845712014545310969.jpg" target="_blank"><img title=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" alt=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/JbwR88iow09HgKt4JqN77g==/2845712014545310969.jpg"></a><a href="http://img.bimg.126.net/photo/BoMz7yDMtCZJa0OdxBHkaQ==/2845712014545310970.jpg" target="_blank"><img title=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" alt=" 如何优化你的php（二） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/BoMz7yDMtCZJa0OdxBHkaQ==/2845712014545310970.jpg"></a></p><p><font size="+2" face="helvetica,verdana,sans-serif"><b><font size="3"><br></font></b></font></p>

<p style="text-align: center;" align="center"><span lang="EN-US">&nbsp;</span></p>

</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/139685482009426113210323</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/139685482009426113210323</guid>
    <pubDate>Tue, 26 May 2009 23:32:10 +0800</pubDate>
    <dcterms:modified>2009-05-26T23:52:53+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[如何优化php（-）]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/13968548200942604156835</link>
    <description><![CDATA[<div><style>
<!--    @font-face  {font-family:宋体;  panose-1:2 1 6 0 3 1 1 1 1 1;  mso-font-alt:SimSun;  mso-font-charset:134;  mso-generic-font-family:auto;  mso-font-pitch:variable;  mso-font-signature:3 135135232 16 0 262145 0;} @font-face  {font-family:"@宋体";  panose-1:2 1 6 0 3 1 1 1 1 1;  mso-font-charset:134;  mso-generic-font-family:auto;  mso-font-pitch:variable;  mso-font-signature:3 135135232 16 0 262145 0;}    p.MsoNormal, li.MsoNormal, div.MsoNormal  {mso-style-parent:"";  margin:0cm;  margin-bottom:.0001pt;  text-align:justify;  text-justify:inter-ideograph;  mso-pagination:none;  font-size:10.5pt;  mso-bidi-font-size:12.0pt;  font-family:"Times New Roman";  mso-fareast-font-family:宋体;  mso-font-kerning:1.0pt;} p  {mso-margin-top-alt:auto;  margin-right:0cm;  mso-margin-bottom-alt:auto;  margin-left:0cm;  mso-pagination:widow-orphan;  font-size:12.0pt;  font-family:宋体;  mso-bidi-font-family:宋体;}    @page  {mso-page-border-surround-header:no;  mso-page-border-surround-footer:no;} @page Section1  {size:612.0pt 792.0pt;  margin:72.0pt 90.0pt 72.0pt 90.0pt;  mso-header-margin:36.0pt;  mso-footer-margin:36.0pt;  mso-paper-source:0;} div.Section1  {page:Section1;}    @list l0  {mso-list-id:153377719;  mso-list-type:hybrid;  mso-list-template-ids:-1127597584 450769930 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1  {mso-level-number-format:alpha-lower;  mso-level-text:"(%1)";  mso-level-tab-stop:24.0pt;  mso-level-number-;  margin-left:24.0pt;  text-indent:-24.0pt;} ol  {margin-bottom:0cm;} ul  {margin-bottom:0cm;} -->
-->--></style>

<p style="text-indent: 21pt;"><span lang="EN-US">翻译：http://phplens.com/lens/php-book/optimizing-debugging-php.php<br></span></p><p style="text-indent: 21pt;"><span lang="EN-US">Php</span><span style="font-family: 宋体;">是一门快速的</span><span lang="EN-US">web</span><span style="font-family: 宋体;">编程开发语言，远比</span><span lang="EN-US">php</span><span style="font-family: 宋体;">代码的执行的速度还有更多需要我们的优化，</span></p>

<p><span style="font-family: 宋体;">这作者的文章中将给你介绍优化你的</span><span lang="EN-US">php</span><span style="font-family: 宋体;">有许多和编码不相关的多个因素，调试我们的</span><span lang="EN-US">php</span><span style="font-family: 宋体;">需要我们理解更多的和</span><span lang="EN-US">php</span><span style="font-family: 宋体;">运行相关的东西，如服务器，找出问题的瓶颈，修复他们，这里将讲述如何调试优化他们，使他们执行的更快。</span></p>

<p><b style=""><span style="font-size: 12pt;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b style=""><span style="font-size: 12pt; font-family: 宋体;">获得更好的性能</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US"></span></b></p>

<p><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">当我们将好的性能的时候，我们不止是讲你的脚步运行的有多快，性能是你的架构和速度之间的平衡，脚步可能用少的资源可能比缓存的执行要慢，但是多个复制的同一个脚步在一个服务器上可以同时执行。</span></p>

<p><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">在下面的例子中，</span><span lang="EN-US">A.php</span><span style="font-family: 宋体;">是一个短跑的能跑的很快，但是</span><span lang="EN-US">B.php</span><span style="font-family: 宋体;">则是一个马拉松选手在一个很长的时间内跑同样的速度，负载比较轻的情况下，</span><span lang="EN-US">A.php</span><span style="font-family: 宋体;">相继会很快，但是网络流量增加时，当</span><span lang="EN-US">A.php</span><span style="font-family: 宋体;">跑完了气力的时候</span><span lang="EN-US">B.php</span><span style="font-family: 宋体;">只是降低了一点。</span></p>

<p style="text-align: center;" align="center"><a href="http://img.bimg.126.net/photo/jVDwLUIQFVtOMa5hCEdLdw==/3169689712739305422.jpg" target="_blank"><img title="如何优化php（-） - 玉树临风 - 小和尚真情无限" alt="如何优化php（-） - 玉树临风 - 小和尚真情无限" src="http://img.bimg.126.net/photo/jVDwLUIQFVtOMa5hCEdLdw==/3169689712739305422.jpg"></a></p>

<p><span style="font-family: 宋体;">让我们举更现实的例子来阐述的更透彻，假设我们需要写一个</span><span lang="EN-US">php</span><span style="font-family: 宋体;">的脚本，来读取一个</span><span lang="EN-US">250k</span><span style="font-family: 宋体;">的文件来生成一个</span><span lang="EN-US">html</span><span style="font-family: 宋体;">的大致内容，写两个</span><span lang="EN-US">php</span><span style="font-family: 宋体;">来做同样一个事情，</span><span lang="EN-US">hare.php</span><span style="font-family: 宋体;">读取一次整个文件到内存，一次性处理文件，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">tortoise.php</span><span style="font-family: 宋体;">读文件，一次读取一行<b>，</b>使内存中不保留更多的内容，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">tortoise.php</span><span style="font-family: 宋体;">但多次读取的时候会变慢，需要更多的系统的调用，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">hare.php</span><span style="font-family: 宋体;">需要</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">0.04</span><span style="font-family: 宋体;">秒和</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">10m</span><span style="font-family: 宋体;">的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">ram</span><span style="font-family: 宋体;">，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">toroise.php</span><span style="font-family: 宋体;">需要</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">0.06</span><span style="font-family: 宋体;">秒和</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">5m</span><span style="font-family: 宋体;">的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">ram</span><span style="font-family: 宋体;">，服务器有</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">100m</span><span style="font-family: 宋体;">的空内存，这时</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">cpu</span><span style="font-family: 宋体;">是</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">99%</span><span style="font-family: 宋体;">的空闲，简单的假设没有内存碎片。</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">跑</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">10</span><span style="font-family: 宋体;">次脚本，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">hare.php</span><span style="font-family: 宋体;">会内存泄漏，在这个时候</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">toroise</span><span style="font-family: 宋体;">还有</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">50m</span><span style="font-family: 宋体;">的空闲内存，当低</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">11</span><span style="font-family: 宋体;">次的时候，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">hare.php</span><span style="font-family: 宋体;">不得不去请开始虚拟内存交换，这使得他的速度将会减少为原来的一般，每次</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">hare.php</span><span style="font-family: 宋体;">的执行，将花费</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">cpu</span><span style="font-family: 宋体;">的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">0.08</span><span style="font-family: 宋体;">秒，同时，</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">toroise.php</span><span style="font-family: 宋体;">将会继续保持原来的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">0.06</span><span style="font-family: 宋体;">秒，在下表中，在不同的负载下快的</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">php</span><span style="font-family: 宋体;">将会用粗体标出：</span><span style="font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">&nbsp;</span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">&nbsp;</span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">&nbsp;</span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">&nbsp;</span></p>

<p><span style="font-family: &quot;Courier New&quot;;" lang="EN-US">&nbsp;</span></p>

<p><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<table style="width: 478.5pt;" width="638" border="1" cellpadding="0" cellspacing="1">
 <tbody><tr style="">
  <td style="padding: 5.25pt; width: 22%;" valign="top" width="22%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: 宋体;">连接</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 24%;" valign="top" width="24%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">1</span><span style="font-size: 12pt; font-family: 宋体;">个</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-size: 12pt; font-family: 宋体;">请求</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">cpu</span><span style="font-size: 12pt; font-family: 宋体;">需要的时间</span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 27%;" valign="top" width="27%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">10</span><span style="font-size: 12pt; font-family: 宋体;">个</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-size: 12pt; font-family: 宋体;">请求</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">cpu</span><span style="font-size: 12pt; font-family: 宋体;">需要的时间</span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 28%;" valign="top" width="28%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">11</span><span style="font-size: 12pt; font-family: 宋体;">个</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">http</span><span style="font-size: 12pt; font-family: 宋体;">请求</span><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">cpu</span><span style="font-size: 12pt; font-family: 宋体;">需要的时间</span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 22%;" valign="top" width="22%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">hare.php
  </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 24%;" valign="top" width="24%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.04</span></b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 27%;" valign="top" width="27%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.40</span></b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 28%;" valign="top" width="28%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.88<br>
  (runs out of RAM) </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
 <tr style="">
  <td style="padding: 5.25pt; width: 22%;" valign="top" width="22%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">tortoise.php
  </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 24%;" valign="top" width="24%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.06 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 27%;" valign="top" width="27%">
  <p style="text-align: left;" align="left"><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.60 </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
  <td style="padding: 5.25pt; width: 28%;" valign="top" width="28%">
  <p style="text-align: left;" align="left"><b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US">0.66</span></b><span style="font-size: 12pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> </span><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US"></span></p>
  </td>
 </tr>
</tbody></table>

<p><span style="font-family: 宋体;">从上面的例子我们将看出，获得好的性能，不仅关系到写好的</span><span lang="EN-US">php</span><span style="font-family: 宋体;">脚本，高性能的</span><span lang="EN-US">php</span><span style="font-family: 宋体;">需要理解硬件，操作系统，以及他支持的软件，如服务器，数据库。</span></p>

<p><b style=""><span style="font-size: 12pt; font-family: 宋体;">瓶颈</span></b><b style=""><span style="font-size: 12pt;" lang="EN-US"></span></b></p>

<p><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">上面的</span><span lang="EN-US">share</span><span style="font-family: 宋体;">和</span><span lang="EN-US">tororse</span><span style="font-family: 宋体;">的例子说明了瓶颈导致慢了下来，有无限多的</span><span lang="EN-US">ram</span><span style="font-family: 宋体;">的时候</span><span lang="EN-US">hare.php</span><span style="font-family: 宋体;">将会永远的比</span><span lang="EN-US">tortoize.php</span><span style="font-family: 宋体;">快，不幸的是，上面的例子有点简单，除了</span><span lang="EN-US">ram</span><span style="font-family: 宋体;">还有许多瓶颈影响。</span></p>

<p style="margin-left: 24pt; text-indent: -24pt;"><span lang="EN-US"><span style="">(a)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;
</span></span></span>网络</p>

<p><span style="font-size: 10.5pt;">你的网络将是最大的瓶颈，假设你有<span lang="EN-US">10m</span>的连接到因特网上，你能在一秒钟输出<span lang="EN-US">1m</span>字节的数据，如果一个页面是<span lang="EN-US">30k</span>，只需要一秒钟<span lang="EN-US">33</span>个页面就使得你饱和，许多微妙的网络瓶颈包括正常的请求到慢的服务如，<span lang="EN-US">dns</span>，分配不够多的内存给网络软件，<span lang="EN-US"></span></span></p>

<p><span lang="EN-US">(b) cpu</span></p>

<p style="text-indent: 21pt;"><span style="font-size: 10.5pt;">如果你监视你的<span lang="EN-US">cpu</span>负载，通过网络发送一个<span lang="EN-US">html</span>页面，不单单要耗费你的<span lang="EN-US">cpu</span>，就像我们提到的瓶颈是网络，但是<span lang="EN-US">php</span>生成的复杂的动态页面，你的<span lang="EN-US">cpu</span>的速度将会变成有限度的因素，多核处理器或者服务器集群能做到。<span lang="EN-US"></span></span></p>

<p><span lang="EN-US">(c) </span>共享内存</p>

<p><span style="font-size: 10.5pt;">共享内存是用在进程内的交换，在多进程中存储资源，比如缓存数据和代码，如果内存分配的不足，任何连接这些用于内存共享，如数据库连接，代码执行等资源都会有很差的性能。<span lang="EN-US"></span></span></p>

<p><span lang="EN-US">(d) </span>文件系统</p>

<p><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp; </span></span>从硬盘中读取数据要比<span lang="EN-US">ram</span>中慢<span lang="EN-US">50</span>到<span lang="EN-US">100</span>倍，文件缓存用<span lang="EN-US">ram</span>能完成这些，尽管低内存的状态讲减少文件缓存中内存利用的次数，文件系统当然也会带来系统碎片，降低硬盘的读取，过多的使用符号链接在<span lang="EN-US">unix</span>系统中将减慢硬盘的读取。</p>

<p>（<span lang="EN-US">e</span>）进程管理</p>

<p>在一些操作系统中，比如<span lang="EN-US">windows</span>中创建一个新进程将是一个很慢的操作，这就意味这<span lang="EN-US">cgi</span>程序需要创建一个新进程在每一个激活的连接中，在这些操作系统中这将非常的慢，在多线程下跑<span lang="EN-US">php</span>可能提高反应的时间。（注：老版本的<span lang="EN-US">php</span>在多线程下不稳定）。</p>

<p><span style="font-size: 10.5pt;">在你的服务器中避免过多的不需要的进程，比如，如果你的服务器只做<span lang="EN-US">web</span>服务器，避免跑甚至装<span lang="EN-US">x-winows</span>在机器上，在<span lang="EN-US">windows</span>上，避免跑微软的查找部分，和三维的屏保会导致<span lang="EN-US">cpu100%.</span></span></p>

<p><span style="font-size: 10.5pt;">一些程序包括你考虑移除掉没有用的网络协议，邮件服务器，杀毒扫描，硬件鼠标驱动，红外线端口，等，在<span lang="EN-US">unix</span>下，加入你连接你的服务器你用<span lang="EN-US">ssh</span>，你可以考虑卸载掉一下：一些守护进程如<span lang="EN-US">:</span></span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> telnetd, inetd, atd, ftpd, lpd, sambad,</span><span style="font-size: 10.5pt;">发送邮件的接受</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">mail</span><span style="font-size: 10.5pt;">，</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">portmap for NFS<br>
xfs, fvwm, xinit, X</span><span style="font-size: 10.5pt;">。</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 10.5pt;">你可以禁用一些各种各样的服务通过修改启动文件，这些文件通常保存在</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">/etc/init* </span><span style="font-size: 10.5pt;">或者</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">/etc/rc*/init*</span><span style="font-size: 10.5pt;">文件下下。</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p><span style="font-size: 10.5pt;">同时查看下你的</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US">crontab</span><span style="font-size: 10.5pt;">文件，你是否需要移除他们，或者重新规划。</span><span style="font-size: 10.5pt; font-family: &quot;Courier New&quot;;" lang="EN-US"></span></p>

<p>（<span lang="EN-US">f</span>）连接其他服务器</p>

<p><span style="font-size: 10.5pt;">如果你的<span lang="EN-US">web</span>服务器需要在其他服务器上运行，可能那些服务器就会成为瓶颈，追普通的例子就是一个很慢的数据库服务器为多个<span lang="EN-US">web</span>服务器上的多个复杂的<span lang="EN-US">sql</span>语句进行服务。<span lang="EN-US"></span></span></p>

<p>花絮：何时优化程序？</p>

<p><span style="font-size: 9pt;">有些人认为拖延到编码完成时进行，这个建议如果是你的编程团队有高质量的编程，你也对你的应用程序有高效的参数有感觉，这样才会很有意义，不然你将会把你推到重写你的部分代码的风险上，在测试后。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 9pt;">我的建议是在设计软件前，你应该做一些基础的测试在你的硬件和软件上，以来得到一些最大的性能，然后你可以设计开发应用程序，期望的参数在脑中，因为每一步，他将会平衡在性能，可用性，安全性，灵活性。<span lang="EN-US"></span></span></p>

<p><span style="font-size: 9pt;">选择好的测试数据，如果你的数据期望存贮<span lang="EN-US">100</span>，<span lang="EN-US">000</span>条记录，避免只测试<span lang="EN-US">100</span>条记录，不然你将会后悔，这曾经发生 在我们公司的一个程序员身上，我们没有检查这个慢的代码，到了后来，导致花费很多时间去重写许多能工作但是不易扩展的代码<span lang="EN-US"></span></span></p>

</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/13968548200942604156835</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/13968548200942604156835</guid>
    <pubDate>Tue, 26 May 2009 00:41:56 +0800</pubDate>
    <dcterms:modified>2009-05-26T00:44:06+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[回忆的介质想到的]]></title>	
    <link>http://liufabin66688.blog.163.com/blog/static/139685482009425112769</link>
    <description><![CDATA[<div>什么是通向回忆的介质？一段歌声，一件旧物，一份情感，也许一切的事物在经过之后，会在我们记忆的神经网络中打下烙印，按照多维的去存储，其中有夹杂着多种参数，就像一个多元的高次的一个方程，至今还未能领会，时间的参数，让这段信息存储的某一维会更深，在人的现实世界种，人有有意识的压迫着这些意识的发展与活跃，故有时候在会出现在我们们中奇怪的现象，就像弗洛伊德的精神分析法，但我们触到这些物质时，这些存贮从相似的东西会产生一种介质，导致我们伤感，导致我们的幸福，让我们大胆的想象，大脑是不是一台更加高级的机器，有自己的运算法则，有自己的存储介质，有自己的算法等。他的算法是不是又一种新的数学分支，比如人脑数学，神经元数学等，人类在这方面是要进行更深的探索，在我看来，这个世界永远是着一套自己运行的法则，自然哲学，自然界的完美，这些很早以前就在探索，地心说，日新说，人们都一直在探索，这种历程还需要走多远？？？？自</div>]]></description>
	    <author><![CDATA[ 小和尚]]></author>
	    <comments>http://liufabin66688.blog.163.com/blog/static/139685482009425112769</comments>
    <slash:comments>0</slash:comments>
    <guid isPermaLink="true">http://liufabin66688.blog.163.com/blog/static/139685482009425112769</guid>
    <pubDate>Mon, 25 May 2009 23:02:07 +0800</pubDate>
    <dcterms:modified>2009-05-25T23:02:07+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[web:  学习]]></title>	
    <link>http://liufabin66688.blog.163.com/prevResource.do?selectId=fks_087070086086088074092083074066087095087075081082094</link>
    <description><![CDATA[<ul>
	<li>
	<a href="http://linux0818.blogspot.com/" target="_blank">一个linux</a>
	: linux学习</li>

	<li>
	<a href="http://www.kerneltravel.net/" target="_blank">linux内核之旅</a>
	: 好的网站</li>

	<li>
	<a href="http://sourceforge.net/projects/xylftp/" target="_blank">西邮的兴趣想小组</a>
	: linux</li>

	<li>
	<a href="http://hi.baidu.com/welcomeheremyfriends/blog" target="_blank">c</a>
	: c</li>

	<li>
	<a href="http://www.php-oa.com/2008/11/08/distress.html" target="_blank">fuwuqi</a>
	: fuwuqi</li>

	<li>
	<a href="http://www.ilia.ws/" target="_blank">phpcreate</a>
	: create</li>

	<li>
	<a href="http://derickrethans.nl/talks.php" target="_blank">超级牛php好东西</a>
	</li>

	<li>
	<a href="http://hi.baidu.com/zengzhaonong/blog" target="_blank">linux</a>
	: linux</li>

	<li>
	<a href="http://blog.chinaunix.net/u/12592/article.html" target="_blank">linux</a>
	: 学习的好地方</li>

	<li>
	<a href="http://blog.chinaunix.net/u2/76292/showart_1329008.html" target="_blank">linux</a>
	: linux</li>

	<li>
	<a href="http://blog.chinaunix.net/u2/63929/article_97977.html" target="_blank">linux小程序</a>
	: 笑程序</li>

	<li>
	<a href="http://blog.chinaunix.net/u/4515/showart_1134020.html" target="_blank">linux命令</a>
	: linux命令</li>

	<li>
	<a href="http://blog.chinaunix.net/u1/53217/article_97612.html" target="_blank">小弟</a>
	: 小弟</li>

	<li>
	<a href="http://student.zjzk.cn/course_ware/data_structure/web/main.htm" target="_blank">数据结构的学习</a>
	: 数据结构的学习</li>

	<li>
	<a href="http://www.herofit.cn/tag/linux/page/3" target="_blank">xuexi</a>
	: xuex</li>

	<li>
	<a href="http://pczou.xplore.cn/index.php?go=category_1&mode=1&page=7" target="_blank">linux高人</a>
	: 高人</li>

	<li>
	<a href="http://mlsx.xplore.cn/" target="_blank">学习linux</a>
	: 学习linux</li>

	<li>
	<a href="http://hi.baidu.com/hustwk/blog/category/larbin%D3%EB%C5%C0%B3%E6" target="_blank">labin</a>
	: labin</li>

	<li>
	<a href="http://hi.baidu.com/hustwk/blog/category/larbin%D3%EB%C5%C0%B3%E6" target="_blank">牛牛草堂</a>
	: 牛牛</li>

	<li>
	<a href="http://www.koven.org/archives/ct4ct9.html" target="_blank">乌秋</a>
	: 秋</li>

	<li>
	<a href="http://oss.lzu.edu.cn/blog/blog.php?do_showone/tid_1540.html" target="_blank">西北忆痕</a>
	: 大牛</li>

	<li>
	<a href="http://blog.chinaunix.net/u/12592/index.html" target="_blank">linuxuni</a>
	: heh</li>

	<li>
	<a href="http://blog.chinaunix.net/u2/76263/article_96475.html" target="_blank">linux</a>
	: linux</li>

	<li>
	<a href="http://www.cppblog.com/sicheng/" target="_blank">cpp</a>
	: cpp</li>

	<li>
	<a href="http://www.cnblogs.com/yizhu2000/archive/2007/12/04/982142.html" target="_blank">web架构</a>
	: web架构</li>

	<li>
	<a href="http://blog.chinaunix.net/u/29134/article_0_2.html" target="_blank">mysql</a>
	: mysql</li>

	<li>
	<a href="http://www.phpobject.net/blog/index.php?mode=1&page=2" target="_blank">phpchina</a>
	: phpchina</li>

	<li>
	<a href="http://www.maycode.com/index.php/hotspot/27-clanguage/839-cache.html" target="_blank">memecached</a>
	: memcached</li>

	<li>
	<a href="http://zhiqiang.org/blog/" target="_blank">好的算法</a>
	</li>

	<li>
	<a href="http://blog.chinaunix.net/u/19185/article_0_1.html" target="_blank">linux</a>
	: cbaidushangde</li>

	<li>
	<a href="http://www.askwan.com/read.php?93" target="_blank">加速器</a>
	: 加速器</li>

	<li>
	<a href="http://www.askwan.com/read.php?11" target="_blank">xcache</a>
	: xcache</li>

	<li>
	<a href="http://www.toplee.com/blog/100.html" target="_blank">eaccletor</a>
	: 加速器</li>

	<li>
	<a href="http://www.upschool.com.cn/edu/1328/2006/624/10du134945_1.shtml" target="_blank">c实例</a>
	: 实例</li>

	<li>
	<a href="http://dodomail.javaeye.com/blog/201025" target="_blank">ip</a>
	: ip</li>

	<li>
	<a href="http://www.cnblogs.com/ewebapp/archive/2006/08/22/483050.html" target="_blank">ip</a>
	: ip</li>

	<li>
	<a href="http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx" target="_blank">gvim</a>
	: gbim</li>

	<li>
	<a href="http://blog.chinaunix.net/u1/51562/index.html" target="_blank">linux内核</a>
	: 学习</li>

	<li>
	<a href="http://man.chinaunix.net/tech/lyceum/linuxK/tlk.html" target="_blank">linux机制</a>
	: linux机制</li>

	<li>
	<a href="http://hi.baidu.com/xproduct/blog/category/web%BF%F2%BC%DC" target="_blank">腾讯的牛人</a>
	: 牛人</li>

	<li>
	<a href="http://www.lupaworld.com/35139/viewspace_16886.html" target="_blank">sed</a>
	: http://www.lupaworld.com/35139/viewspace_16886.html</li>

	<li>
	<a href="http://blog.chinaunix.net/u1/59178/article.php?frmid=75988" target="_blank">服务器</a>
	: 服务器</li>

	<li>
	<a href="http://blog.chinaunix.net/u2/60913/showart_1162310.html" target="_blank">linxu</a>
	: linux</li>

	<li>
	<a href="http://blog.chinaunix.net/u/22935/article_36498.html" target="_blank">linux c 学习</a>
	: 学习</li>

	<li>
	<a href="http://blog.chinaunix.net/u2/72003/showart_1162522.html" target="_blank">linux c</a>
	: linux c</li>

	<li>
	<a href="http://hi.baidu.com/mgqw/blog/item/ff45563fab9ca7c77d1e71be.html" target="_blank">linux 书籍</a>
	: linux 书籍</li>

	<li>
	<a href="http://hi.baidu.com/mgqw" target="_blank">linux c</a>
	: linux c</li>

	<li>
	<a href="http://blog.chinaunix.net/u/5252/showart_1161941.html" target="_blank">linux</a>
	: linux</li>

	<li>
	<a href="http://blog.chinaunix.net/u1/53217/article_70407.html" target="_blank">linux</a>
	: linux</li>

	<li>
	<a href="http://www.libing.net.cn/index.php" target="_blank">吉大</a>
	: linux</li>

	<li>
	<a href="http://glemir.xplore.cn/?p=37" target="_blank">yahoo</a>
	: yahoo</li>

	<li>
	<a href="http://shiflett.org/articles" target="_blank">国外的</a>
	: 国外</li>

	<li>
	<a href="http://blog.chinaunix.net/u/6303/showart_432440.html" target="_blank">niuren</a>
	</li>

	<li>
	<a href="http://hi.baidu.com/yanyulou/blog/item/728ba344709aea81b3b7dc6d.html" target="_blank">vi</a>
	: vi学习</li>

	<li>
	<a href="http://www.bradfitz.com/" target="_blank">memcached</a>
	: memached到作者</li>

	<li>
	<a href="http://www.whenpenguinsattack.com/category/php-security/" target="_blank">php学习地址</a>
	: 学习</li>

	<li>
	<a href="http://www.phpbuilder.com/board/showthread.php?t=10357309" target="_blank">国外网站</a>
	: 国外</li>

	<li>
	<a href="http://weierophinney.net/matthew/archives/164-Vim-Productivity-Tips-for-PHP-Developers.html" target="_blank">php开发人员</a>
	: zendframewok</li>

	<li>
	<a href="http://www.akrabat.com" target="_blank">zendframework</a>
	: 框架开发人员</li>

	<li>
	<a href="http://www.php.net/manual/zh/types.comparisons.php" target="_blank">函数比较</a>
	</li>

	<li>
	<a href="http://www.hightman.cn/index.php?weblog" target="_blank">mylql</a>
	</li>

	<li>
	<a href="http://www.hiadmin.com/?p=188" target="_blank">高性能</a>
	</li>

	<li>
	<a href="http://www.xianguo.com/service/share/1036489/3" target="_blank">好的学习的地方</a>
	</li>

	<li>
	<a href="http://yanhuan02.blog.163.com" target="_blank">星星 的网易博客</a>
	: 星星 的网易博客</li>

	<li>
	<a href="http://www.iamdcboy.com/article.asp?id=259" target="_blank">安全</a>
	: 安全</li>

	<li>
	<a href="http://blog.s135.com/read.php/318.htm" target="_blank">新浪网张宴</a>
	</li>

	<li>
	<a href="http://www.vchelp.net/blog/wyy/" target="_blank">vc的</a>
	: vc的</li>

	<li>
	<a href="http://blog.csdn.net/shfabjc/" target="_blank">小熊的</a>
	: 可以</li>

	<li>
	<a href="http://www.cnblogs.com/mgod/" target="_blank">学习.net的</a>
	: 博客</li>
</ul>]]></description>
	    <author><![CDATA[liufabin66688]]></author>
    <guid isPermaLink="false">collection/static/fks_087070086086088074092083074066087095087075081082094</guid>
    <pubDate>Thu, 19 Jul 2007 16:07:03 +0800</pubDate>
    <dcterms:modified>2007-07-19T16:07:03+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[web:  文学]]></title>	
    <link>http://liufabin66688.blog.163.com/prevResource.do?selectId=fks_087065082081087068084083074066087095087075081082094</link>
    <description><![CDATA[<ul>
	<li>
	<a href="http://0106551513.blog.163.com" target="_blank">伤感的恋人 的网易博客</a>
	: C#网络编程概述</li>

	<li>
	<a href="http://ftw118.blog.163.com" target="_blank">ftw118 的网易博客</a>
	: ftw118 的网易博客C#网络编程</li>

	<li>
	<a href="http://kevindash.blog.163.com" target="_blank">纤尘 的网易博客</a>
	: 大量的学习c#的资料</li>

	<li>
	<a href="http://blog.163.com/tsdzqq@126" target="_blank">小郎 的网易博客</a>
	: 小郎 的网易博客 c#技巧</li>

	<li>
	<a href="http://gaomenggaici.blog.163.com" target="_blank">高猛 的网易博客</a>
	: 高猛 的网易博客</li>

	<li>
	<a href="http://maosea0125.blog.163.com" target="_blank">潇洒雨鞋 的网易博客</a>
	: 潇洒雨鞋 的网易博客</li>

	<li>
	<a href="http://blog.sina.com.cn/u/1230313060" target="_blank">化蝶的BLOG</a>
	: 一曲粱祝音,惊为天上人.</li>
</ul>]]></description>
	    <author><![CDATA[liufabin66688]]></author>
    <guid isPermaLink="false">collection/static/fks_087065082081087068084083074066087095087075081082094</guid>
    <pubDate>Fri, 18 May 2007 19:59:51 +0800</pubDate>
    <dcterms:modified>2007-05-18T19:59:51+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[web:  友情网址]]></title>	
    <link>http://liufabin66688.blog.163.com/prevResource.do?selectId=fks_087066082083088067084085074066087095087075081082094</link>
    <description><![CDATA[<ul>
	<li>
	<a href="http://jackywdx.cn/" target="_blank">鸭嘴的博客</a>
	: 关注lamp</li>

	<li>
	<a href="http://seaprince.cn/" target="_blank">海洋之星</a>
	: 牛牛的海哥</li>

	<li>
	<a href="http://techippo.org/" target="_blank">atom</a>
	: 牛叉叉</li>

	<li>
	<a href="http://my.benorz.org/" target="_blank">ben的</a>
	: 学习</li>

	<li>
	<a href="http://www.karmaer.com/" target="_blank">谦哥地盘</a>
	: 学习</li>

	<li>
	<a href="http://www.centoschina.com/" target="_blank">centos中国</a>
	: 看名可知</li>

	<li>
	<a href="http://hi.baidu.com/j_fo/blog/item/7412bb01bcb0ee00738da5d1.html" target="_blank">linxu学习</a>
	: 学习linux</li>

	<li>
	<a href="http://www.hiadmin.com/%E5%AF%B9%E6%AF%94-apc-vs-eaccelerator-vs-xcache-eaccelerator%E8%83%9C%E5%87%BA/" target="_blank">高手</a>
	: 网站</li>

	<li>
	<a href="http://forums.pligg.com/pligg-tutorials/8466-sidebar-friends-module-messaging-activity.html" target="_blank">slider</a>
	: h</li>

	<li>
	<a href="http://www.phpbuilder.com/board/showthread.php?t=10351826" target="_blank">国外论坛</a>
	</li>

	<li>
	<a href="http://www.programmingtalk.com/showthread.php?t=46442" target="_blank">国外的php</a>
	: bucuo</li>

	<li>
	<a href="http://www.ideagrace.com/blog/" target="_blank">好的php</a>
	: 不错的</li>

	<li>
	<a href="http://www.seoip.net/seoblog.htm" target="_blank">seo</a>
	: 学习</li>

	<li>
	<a href="http://our.uni.cc/blog/users/nana/index.php/show/one/id/10" target="_blank">zf</a>
	: zf</li>

	<li>
	<a href="http://blog.sina.com.cn/cuikai" target="_blank">web design</a>
	: ck</li>

	<li>
	<a href="http://blog.sina.com.cn/gxllingblog" target="_blank">郭小玲</a>
	: 淑女</li>

	<li>
	<a href="http://forums.devshed.com/php-development-5/" target="_blank">老外的php论坛</a>
	: 有c语言的</li>

	<li>
	<a href="http://simon.net.nz/articles/process-a-url-query-string-in-php/" target="_blank">eng</a>
	: 老外blog</li>

	<li>
	<a href="http://blog.csdn.net/baggio785/archive/2006/09/12/1215172.aspx" target="_blank">讲大型的</a>
	: 比较深</li>

	<li>
	<a href="http://www.ccvita.com/index.php/category/php" target="_blank">玉面修罗</a>
	: 村里的</li>

	<li>
	<a href="http://www.quickshare.com.cn/post/windowsXP-php-Apache-Mysql-Zend-Configuration.php" target="_blank">有空看看</a>
	: 八错</li>

	<li>
	<a href="http://blog.csdn.net/heiyeshuwu/archive/2006/11/13/1380838.aspx" target="_blank">黑夜明灯</a>
	: memcached的解析</li>

	<li>
	<a href="http://blog.chinaunix.net/u/8780/article.html" target="_blank">比较全的网站</a>
	: 算法，安全。。。</li>

	<li>
	<a href="http://www.cnblogs.com/soplayer/" target="_blank">搞java的</a>
	: java的</li>

	<li>
	<a href="http://sunxingfang.cn/article.asp?id=160" target="_blank">孙兴芳</a>
	: 恩</li>

	<li>
	<a href="http://www.toplee.com/blog/category/%e6%8a%80%e6%9c%af/php" target="_blank">应该很牛</a>
	: 不错</li>

	<li>
	<a href="http://seaprince.cn/t/160/1/" target="_blank">群里的工程师</a>
	: 还可以了</li>

	<li>
	<a href="http://hi.baidu.com/sungoogle/blog" target="_blank">百度空间</a>
	: 还不错</li>

	<li>
	<a href="http://conanmusic.spaces.live.com/" target="_blank">我见过最牛的phper</a>
	: 真正的牛人</li>

	<li>
	<a href="http://blog.sina.com.cn/u/1418859182" target="_blank">西大浪人</a>
	: 新浪的牛人</li>

	<li>
	<a href="http://blog.csdn.net/phpme/archive/2006/06/02/769247.aspx" target="_blank">csdn上的牛人</a>
	: 高屋建瓴</li>

	<li>
	<a href="http://blog.chinaunix.net/u/12228/showart_219258.html" target="_blank">欣然随风</a>
	: 村里的牛人</li>

	<li>
	<a href="http://100000.myabc.cn/home/gbook.htm" target="_blank">火星上的来客</a>
	: 火星</li>

	<li>
	<a href="http://www.x2blog.cn/Maxwin/#sid.19729/page.1/" target="_blank">享受分享</a>
	: 享受分享xeblog</li>

	<li>
	<a href="http://www.cnblogs.com/lovecherry/archive/2005/03/26/126102.html" target="_blank">LoveCherry</a>
	: asp.net</li>

	<li>
	<a href="http://blog.csdn.net/pfworld/archive/2007/03/22/1537413.aspx" target="_blank">pfworld的专栏</a>
	: asp.net</li>

	<li>
	<a href="http://blog.chinaunix.net/u/25374/showart_192583.html" target="_blank">“开源”盛世</a>
	: “开源”盛世 javajavascript实现</li>

	<li>
	<a href="http://www.gx3.cn/" target="_blank">死神</a>
	: 东京电子学院的</li>

	<li>
	<a href="http://wulonghack.blog.163.com" target="_blank">wulonghack 的网易博客</a>
	: wulonghack 的网易博客</li>

	<li>
	<a href="http://wulonghack.blog.163.com/blog/277167992007423104944796.track" target="_blank">sql注入详解</a>
	: sql注入详解</li>

	<li>
	<a href="http://blog.csdn.net/fzm010/category/293249.aspx" target="_blank">分析diszum的牛</a>
	: 分析diszum的牛php学习</li>

	<li>
	<a href="http://www.cpcwedu.com/Document/WEBOfficial/095447158.htm" target="_blank">rss2.0标准</a>
	: rss2.0标准</li>

	<li>
	<a href="http://blog.csdn.net/wsyl_czl/archive/2005/01/11/248835.aspxhttp://blog.csdn.net/xiaoxiaohai123/archive/2007/05/11/1604928.aspx" target="_blank">得到</a>
	: 得到</li>

	<li>
	<a href="http://blog.csdn.net/xiaoxiaohai123/archive/2007/05/17/1613263.aspx" target="_blank">图片存入数据库</a>
	: 图片存入数据库</li>

	<li>
	<a href="http://www.28star.com/blog/article.asp?id=286" target="_blank">c#socket</a>
	: c#socket</li>

	<li>
	<a href="http://www.21ds.net/article/21/26161" target="_blank">c#文件传输</a>
	: c#文件传输</li>

	<li>
	<a href="http://www.blueidea.com/tech/program/2004/1810_3.asp" target="_blank">兰色理想</a>
	: sql注入了解</li>

	<li>
	<a href="http://blog.csdn.net/conanlwl/archive/2007/05/11/1604941.aspx" target="_blank">图asp.net</a>
	: 呵呵不错啊！</li>

	<li>
	<a href="http://blog.csdn.net/21aspnet/archive/2007/03/24/1539846.aspx" target="_blank">asp.net</a>
	: 真牛</li>

	<li>
	<a href="www.ajaxcn.org" target="_blank">ajax实战的作者</a>
	: 李捆</li>

	<li>
	<a href="http://www.phpchina.com/8051/viewspace_3582.html" target="_blank">文件上传的详细</a>
	: 可以吧</li>

	<li>
	<a href="http://kissfishaiziji.blog.163.com" target="_blank">kissfish 的网易博客</a>
	: kissfish 的网易博客</li>

	<li>
	<a href="http://zhaojianguang811.blog.163.com" target="_blank">frozen 的网易博客</a>
	: frozen 的网易博客</li>

	<li>
	<a href="http://hoho.zs.blog.163.com" target="_blank">hoho 的网易博客</a>
	: hoho 的网易博客</li>

	<li>
	<a href="http://blog.sina.com.cn/phpyy#albumPic_4ab0d13505000k34_1" target="_blank">朱武杰的</a>
	: 牛</li>

	<li>
	<a href="http://www.phzzy.org/index.php?tag=php" target="_blank">看按</a>
	: php</li>

	<li>
	<a href="http://www.dodo.hk/default.asp?cat=7" target="_blank">小牛</a>
	: javacript</li>

	<li>
	<a href="http://www.itfly.com/blog/default.asp?cat=14" target="_blank">牛人的</a>
	: php</li>
</ul>]]></description>
	    <author><![CDATA[liufabin66688]]></author>
    <guid isPermaLink="false">collection/static/fks_087066082083088067084085074066087095087075081082094</guid>
    <pubDate>Thu, 26 Apr 2007 22:40:21 +0800</pubDate>
    <dcterms:modified>2007-04-26T22:40:21+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[music:  张学友]]></title>	
    <link>http://liufabin66688.blog.163.com/prevResource.do?selectId=fks_087066086095080074092095074066087095087075081082094</link>
    <description><![CDATA[<ul></ul>]]></description>
	    <author><![CDATA[liufabin66688]]></author>
    <guid isPermaLink="false">collection/static/fks_087066086095080074092095074066087095087075081082094</guid>
    <pubDate>Sat, 21 Apr 2007 18:00:01 +0800</pubDate>
    <dcterms:modified>2007-04-21T18:00:01+08:00</dcterms:modified>
  </item>    
  <item>
  	<title><![CDATA[book:  学习]]></title>	
    <link>http://liufabin66688.blog.163.com/prevResource.do?selectId=fks_087066085095089074093083074066087095087075081082094</link>
    <description><![CDATA[<ul></ul>]]></description>
	    <author><![CDATA[liufabin66688]]></author>
    <guid isPermaLink="false">collection/static/fks_087066085095089074093083074066087095087075081082094</guid>
    <pubDate>Wed, 18 Apr 2007 22:14:32 +0800</pubDate>
    <dcterms:modified>2007-04-18T22:14:32+08:00</dcterms:modified>
  </item>    
 </channel>
</rss>