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

<channel>
	<title>风雪之隅 &#187; Linux/Unix</title>
	<atom:link href="http://www.laruence.com/category/os/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP应用,PHP源码分析,Zend引擎分析,Web相关技术研究,Web技术分享 - 左手代码 右手诗</description>
	<lastBuildDate>Sat, 04 Sep 2010 15:10:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BTwitter(Twitter In Bash)</title>
		<link>http://www.laruence.com/2010/05/24/1526.html</link>
		<comments>http://www.laruence.com/2010/05/24/1526.html#comments</comments>
		<pubDate>Mon, 24 May 2010 14:31:01 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[btwitter]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1526</guid>
		<description><![CDATA[    完成了第一版的bTwitter, 完美支持linux命令行下使用推特.
  
    有几点说明:
<coolcode lang="bash" linenum="off">
1. 脚本假设终端是UTF-8的, 如果不是, 请自行iconv之类的.
2. 脚本中in_reply_to, 不知何故, 不能正常在推下方显示, 谁知道为什么?
3. 新浪微薄的API地址,调用很类似, 可以方便的修改以后用到新浪微薄中.
</coolcode>
    
    下载:<a href="http://code.google.com/p/btwitter/downloads/list" target="_blank">http://code.google.com/p/btwitter/downloads/list</a>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/05/24/1526.html"  title="Permanet Link to BTwitter(Twitter In Bash)" >http://www.laruence.com/2010/05/24/1526.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    完成了第一版的bTwitter, 完美支持linux命令行下使用推特.</p>
<p>    有几点要说明的:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
1. 脚本假设终端是UTF-8的, 如果不是, 请自行iconv之类的.
2. 脚本中in_reply_to, 不知何故, 不能正常在推下方显示, 谁知道为什么?
3. 新浪微薄的API地址,调用很类似, 可以方便的修改以后用到新浪微薄中.
</pre>
<p>    现在支持:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
Usage：
	btwitter content    		发表Twitter
	btwitter -l|--list[USER]	查看[USER]的最新Twitter
	btwitter -f|--friend[ SIZE]	查看最新的[SIZE条]朋友更新
	btwitter -m|--mentions		查看最新的[SIZE条]@laruence
</pre>
<p>    下载:<a href="http://code.google.com/p/btwitter/downloads/list"  target="_blank" >http://code.google.com/p/btwitter/downloads/list</a></p>
<p>    展示部分参考了<a href="http://blog.dickeny.com/343.html"  target="_blank" >沈觅仁的笔记本</a>中的部分逻辑, 修复了不能显示中文, 以及sed正则的问题, 美化了输出等. </p>
<p>   使用截图:<br/>
<div id="attachment_1530"  class="wp-caption aligncenter"  style="width: 310px" ><a href="http://www.laruence.com/wp-content/uploads/metion.jpg" ><img src="http://www.laruence.com/wp-content/uploads/metion-300x49.jpg"  alt=""  title="metion"  width="300"  height="49"  class="size-medium wp-image-1530" /></a><p class="wp-caption-text" >metion</p></div><br/>
<div id="attachment_1529"  class="wp-caption aligncenter"  style="width: 310px" ><a href="http://www.laruence.com/wp-content/uploads/list.jpg" ><img src="http://www.laruence.com/wp-content/uploads/list-300x63.jpg"  alt="List"  title="list"  width="300"  height="63"  class="size-medium wp-image-1529" /></a><p class="wp-caption-text" >List</p></div></p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2652" >2010/05/24</a>, <a href="http://www.laruence.com/2010/05/24/1515.html"  rel="external nofollow"  class="url" >shell下发推脚本 | 风雪之隅</a> writes: [...] 请参看最新的bTwitter. [...]</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2653" >2010/05/25</a>, <a href="http://skiyo.cn"  rel="external nofollow"  class="url" >Jessica</a> writes: 汗..原来是个bush脚本..

PS 我的验证码是dan 我想后面加个疼.</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2654" >2010/05/25</a>, 小熊 writes: 劳伦斯叔叔太强大了</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2655" >2010/05/25</a>, <a href="http://topsy.com/trackback?utm_source=pingback&amp;utm_campaign=L2&amp;url=http://www.laruence.com/2010/05/24/1526.html"  rel="external nofollow"  class="url" >Tweets that mention BTwitter(Twitter In Bash) | 风雪之隅 -- Topsy.com</a> writes: [...] This post was mentioned on Twitter by miracle, fury, Madog, notsobad, notsobad and others. notsobad said: *****http://www.laruence.com/2010/05/24/1526.html [...]</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2664" >2010/05/26</a>, <a href="http://glemir.xplore.cn"  rel="external nofollow"  class="url" >glemir</a> writes: 这个比较帅</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2675" >2010/05/27</a>, evan writes: encodeURL 方法似乎有问题，不能发推，接收没问题。注释掉之后就能正常发推了</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2676" >2010/05/27</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @evan 输入是UTF-8编码么?</li><li><a href="http://www.laruence.com/2010/05/24/1526.html#comment-2732" >2010/06/10</a>, <a href="http://www.xingai114.com"  rel="external nofollow"  class="url" >xingai</a> writes: 这个比较帅............</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/05/24/1526.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>shell下发推脚本</title>
		<link>http://www.laruence.com/2010/05/24/1515.html</link>
		<comments>http://www.laruence.com/2010/05/24/1515.html#comments</comments>
		<pubDate>Mon, 24 May 2010 08:08:19 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1515</guid>
		<description><![CDATA[   Be Lazy, 懒得能不动鼠标, 就不愿动鼠标..

   今天在推上看到有人的下面缀着"via bash", 好奇怎么做到, 找来推的API, 其实挺简单..

   直接上代码, 不解释了, 只是有几点解释下
<coolcode lang="sh" linenum="off">
1. 如果是VPN, 不用代理, 就取消-x选项
2. 脚本直接从STDIN读取内容,内容需要是UTF-8编码, 如果你的终端不是, 那请在脚本中添加iconv
3. 做到完全脚本浏览/发推也是可以的.
4. 新浪微薄也有REST API, 理论上也是可以这么搞的.
</coolcode>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/05/24/1515.html"  title="Permanet Link to shell下发推脚本" >http://www.laruence.com/2010/05/24/1515.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>
   Be Lazy, 懒得能不动鼠标, 就不愿动鼠标..</p>
<p>   今天在推上看到有人的下面缀着&#8221;via bash&#8221;, 好奇怎么做到, 找来推的API, 其实挺简单..</p>
<p>   请参看最新的<a href="http://www.laruence.com/2010/05/24/1526.html" >bTwitter</a>.</p>
<p>   直接上代码, 不解释了, 只是有几点解释下</p>
<pre name="code"  class="sh_sh"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
1. 如果是VPN, 不用代理, 就取消-x选项
2. 脚本直接从STDIN读取内容,内容需要是UTF-8编码, 如果你的终端不是, 那请在脚本中添加iconv
3. 做到完全脚本浏览/发推也是可以的.
4. 新浪微薄也有REST API, 理论上也是可以这么搞的.
</pre>
<p>   代码:</p>
<pre name="code"  class="sh_sh"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
#!/bin/bash
#by laruence&lt;http://www.laruence.com&gt;

USERNAME=&quot;用户名&quot;
PASSWORD=&quot;密码&quot;
PROXY=&quot;代理地址&quot;

function encodeurl() {
    echo &quot;$*&quot; | awk 'BEGIN {
        split (&quot;1 2 3 4 5 6 7 8 9 A B C D E F&quot;, hextab, &quot; &quot;)
        hextab [0] = 0
        for (i=1; i&lt;=255; ++i) {
            ord [ sprintf (&quot;%c&quot;, i) &quot;&quot; ] = i + 0
        }
    }
    {
        encoded = &quot;&quot;
        for (i=1; i&lt;=length($0); ++i) {
            c = substr ($0, i, 1)
            if ( c ~ /[a-zA-Z0-9.-$]/ ) {
                encoded = encoded c             #不需要编码
            } else if ( c == &quot; &quot; ) {
                encoded = encoded &quot;+&quot;  #处理空格
            } else {
                #编码
                lo = ord [c] % 16
                hi = int (ord [c] / 16);
                encoded = encoded &quot;%&quot; hextab [hi] hextab [lo]
            }
        }
        print encoded
    }' 2&gt;/dev/null
}

URL=https://api.twitter.com/1/statuses/update.xml

CONTENT=$*
REPLY=`echo $CONTENT | sed -n -e 's/^.*@\([^ ]\+\).*$/\1/p'`

DATA=`encodeurl $CONTENT`

POST=&quot;source=bash&amp;status=$DATA&quot;

#in_reply_to老是不能在下面显示出来, 不知何故
if [ -n &quot;$REPLY&quot; ]
then
    POST=$POST&quot;&amp;in_reply_to=&quot;$REPLY
fi  

MESSAGE=`curl -3 -k --silent -x$PROXY -u$USERNAME:$PASSWORD -d&quot;$POST&quot; $URL`

exit 0
</pre>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_sh.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_sh.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2646" >2010/05/24</a>, <a href="http://www.54chen.com"  rel="external nofollow"  class="url" >54chen</a> writes: http://www.54chen.com/_linux_/ssh-twitter-client.html 分享一下perl的版本</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2647" >2010/05/24</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @54chen Perl也是Linux标准配备, 顶.</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2650" >2010/05/24</a>, <a href="http://pityonline.info"  rel="external nofollow"  class="url" >pityonline</a> writes: 贵博代码粘贴后每行都多了行号，还要手动去删除。最好换个能保留文件原来的编辑器……</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2651" >2010/05/24</a>, Brilliance writes: 我的UTF8发出去的汉字是***= =!</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2656" >2010/05/25</a>, <a href="http://topsy.com/trackback?utm_source=pingback&amp;utm_campaign=L2&amp;url=http://www.laruence.com/2010/05/24/1515.html"  rel="external nofollow"  class="url" >Tweets that mention shell下发推脚本 | 风雪之隅 -- Topsy.com</a> writes: [...] This post was mentioned on Twitter by 阿才, 大路阿神. 大路阿神 said: 【人肉GR分享】shell下发推脚本 http://www.laruence.com/2010/05/24/1515.html [...]</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2891" >2010/07/08</a>, <a href="http://herrick5.com"  rel="external nofollow"  class="url" >AWu</a> writes: 靠谱！

mark了～</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2892" >2010/07/08</a>, <a href="http://herrick5.com"  rel="external nofollow"  class="url" >AWu</a> writes: #in_reply_to老是不能在下面显示出来, 不知何故？

这个是什么意思？
如果是转义的话，你可以考虑用单引号～</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-2939" >2010/07/15</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @AWu 就是在一条twitter下面会显示 :   about * hours ago  via web  in reply to somebody</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-3014" >2010/07/30</a>, <a href="http://www.commentset.com"  rel="external nofollow"  class="url" >mahone</a> writes: 这样就能绕过GFW了？如果是的话请告之原理，谢谢。
还是只是一个发帖查看的简单工具？</li><li><a href="http://www.laruence.com/2010/05/24/1515.html#comment-3016" >2010/07/31</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @mahone 不会, 还需要借助代理, 或者VPN.</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/05/24/1515.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Le Putty &#8211; Putty with Zmodem</title>
		<link>http://www.laruence.com/2010/04/21/1442.html</link>
		<comments>http://www.laruence.com/2010/04/21/1442.html#comments</comments>
		<pubDate>Wed, 21 Apr 2010 05:08:53 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[le putty]]></category>
		<category><![CDATA[rz]]></category>
		<category><![CDATA[sz]]></category>
		<category><![CDATA[z-modem]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1442</guid>
		<description><![CDATA[ 一直使用putty(pietty), 因为简单,小巧.

    但是, 一直也羡慕SecureCRT支持sz/rs进行file transfer, 很简单,,,很方便... 而小Putty就只能借助ftp或者winscp了....
   
    今天发现了一个基于Putty的改进版Le Putty(项目地址:<a href="http://sourceforge.net/projects/leputty/" target="_blank">http://sourceforge.net/projects/leputty/</a>), 可以完美的支持ZModem进行file transfer.]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2010/04/21/1442.html"  title="Permanet Link to Le Putty &#8211; Putty with Zmodem" >http://www.laruence.com/2010/04/21/1442.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    一直使用putty(pietty), 因为简单,小巧.</p>
<p>    但是, 一直也羡慕SecureCRT支持sz/rs进行file transfer, 很简单,,,很方便&#8230; 而小Putty就只能借助ftp或者winscp了&#8230;.</p>
<p>    今天发现了一个基于Putty的改进版Le Putty(项目地址:<a href="http://sourceforge.net/projects/leputty/"  target="_blank" >http://sourceforge.net/projects/leputty/</a>), 可以完美的支持ZModem进行file transfer.</p>
<p>    下载<a href="http://sourceforge.net/projects/leputty/files/leputty/leputtyTrunk-2006-10-03/LePuttyTrunk-bin-20061103.zip/download" >Le Putty</a>以后, 解压到自己的目录.</p>
<p>    在目录中, 解压lsrz, 然后在Le Putty中Setting->ZModem中, 将sz和rz路径指向从lsrz中解压出来的对应可执行文件, 并设置好本地接受文件目录.</p>
<p>    接下来, 登录服务器, </p>
<p>    1. 下载:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
 $ sz  file
</pre>
<p>    然后在Le Putty的标题栏右键, 选择ZModem Recive&#8230;</p>
<p>    2. 上传:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
 $ rz
</pre>
<p>    然后在Le Putty的标题栏右键, 选择ZModem Upload&#8230;</p>
<p>   不足: 找不到显示Menu Bar的设置,,,, 也没有像pietty那样初始的简单登录界面., 不过,, 这些都是可以忍受的, <img src="http://www.laruence.com/wp-includes/images/smilies/icon_wink.gif"  alt=";)"  class="wp-smiley" />
</p>
<p>  <script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2531" >2010/04/21</a>, evan writes: putty 可以用 scp</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2532" >2010/04/21</a>, Platinum writes: 一直在 SecureCRT 下用 scp 的路过</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2533" >2010/04/21</a>, <a href="http://sanmuding.com"  rel="external nofollow"  class="url" >Anders</a> writes: putty上传不是问题，下载不行， 

上传直接将 文件拖动到putty上就可以上传了。

下载的话就是 winscp了。</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2534" >2010/04/21</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @anders 在我们公司,,上传,winscp都不行, 因为不是直接连接, 需要中转...</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2538" >2010/04/24</a>, zwws writes: XShell支持, 一直在用, 而且对个人用户的免费的.</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2542" >2010/04/28</a>, alewater writes: 百度应该是用的relay机器做的中转，还有可恶的token密码，防止密码被盗。</li><li><a href="http://www.laruence.com/2010/04/21/1442.html#comment-2557" >2010/05/09</a>, <a href="http://www.afeii.com"  rel="external nofollow"  class="url" >飞猪</a> writes: 来了就顶顶。。</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/04/21/1442.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>用Vim写Blog</title>
		<link>http://www.laruence.com/2010/04/17/1433.html</link>
		<comments>http://www.laruence.com/2010/04/17/1433.html#comments</comments>
		<pubDate>Sat, 17 Apr 2010 03:57:02 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[xml-rpc]]></category>

		<guid isPermaLink="false">http://www.laruence.com/2010/04/17/1433.html</guid>
		<description><![CDATA[Vim是一种毒品，一旦你习惯之后就无法离开：），写Blog也是如此。以前用Vim写Blog是依赖Vimperator可以调出Vim进行编辑，不过今天发现了更简便、连游览器都不需要开的方法，那就是Vim的Blog插件：vimpress。vimpress支持获取文章列表并编辑修改文件、新建文章、现场保存，并支持文章分类、标签。]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>本文地址: <a href="http://www.laruence.com/2010/04/17/1433.html"  title="Permanet Link to 用Vim写Blog" >http://www.laruence.com/2010/04/17/1433.html</a></li>
<li>文章转自: <a href="http://www.imv0m.com/?p=512"  target="_blank" >Venom</a></li>
</ul></div>
<p>Vim是一种毒品，一旦你习惯之后就无法离开：），写Blog也是如此。以前用Vim写Blog是依赖Vimperator可以调出Vim进行编辑，不过今天发现了更简便、连游览器都不需要开的方法，那就是Vim的Blog插件：vimpress。vimpress支持获取文章列表并编辑修改文件、新建文章、现场保存，并支持文章分类、标签。</p>
<p>PS：这篇文章就是我使用vimpress直接在gVim中完成的。</p>
<p>需注意的是，vimpress仅支持xlmrpc，下载前请先检查你的Blog是否具有xlmrpc功能！具体关于xlmrpc的信息请访问http://zh.wikipedia.org/zh-cn/XML-RPC</p>
<p>vimpress的下载地址在http://www.vim.org/scripts/script.php?script_id=1953</p>
<p>下载完vimpress之后，将插件对应文件夹放入。然后编辑blog.vim找到并修改以下代码。</p>
<pre name="code"  class="sh_python"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
command! -nargs=0 BlogList exec(&quot;py blog_list_posts()&quot;)
command! -nargs=0 BlogNew exec(&quot;py blog_new_post()&quot;)
command! -nargs=0 BlogSend exec(&quot;py blog_send_post()&quot;)
command! -nargs=1 BlogOpen exec('py blog_open_post(&lt;f-args&gt;)')
python &lt;&lt;EOF
# -*- coding: utf-8 -*-
import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re

#####################
#      Settings     #
#####################

enable_tags = 1
blog_username = 'Test' #你用于登陆Blog的账户名
blog_password = 'Test' #你的Blog账户的地址
blog_url = 'http://www.test.com/xmlrpc.php' #你的Blog的xmlrpc文件地址  

#####################
# Do not edit below #
#####################

handler = xmlrpclib.ServerProxy(blog_url).metaWeblog
edit = 1

def blog_edit_off():
  global edit
  if edit:
    edit = 0
    for i in [&quot;i&quot;,&quot;a&quot;,&quot;s&quot;,&quot;o&quot;,&quot;I&quot;,&quot;A&quot;,&quot;S&quot;,&quot;O&quot;]:
    .....省略
</pre>
<p>然后重新启动你的Vim即可，以下是vimpress的命令清单。</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
:BlogList #列出Blog里的文章
:BlogNew #创建新文章
:BlogOpen ID #打开ID为“”的文章
:BlogSend #发布文章
</pre>
<p>vimpress的格式为：</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&quot;Strid #你的文章的ID
&quot;Title #文章的标题
&quot;Cats #文章分类，如有多个分类需建立多个Cats
&quot;Tags #文章标签，多个标签需中间加入，空格
</pre>
<p>转载标注: 如果是wordpress, 在setting->writing中开启xml-rpc既可以使用. 不过目前不支持excerpt和custom fields, 比较郁闷.<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_python.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2517" >2010/04/18</a>, 小熊 writes: 小熊来拜雪候鸟锅锅</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2519" >2010/04/18</a>, <a href="http://topsy.com/trackback?utm_source=pingback&amp;utm_campaign=L2&amp;url=http://www.laruence.com/2010/04/17/1433.html"  rel="external nofollow"  class="url" >Tweets that mention 用Vim写Blog -- Topsy.com</a> writes: [...] This post was mentioned on Twitter by Jerry Wang, 开瓢android机器人. 开瓢android机器人 said: 用Vim写Blog http://goo.gl/fb/TvtOr [...]</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2522" >2010/04/18</a>, Yufeng writes: 哈哈，的确是会上瘾的，也说不上来为啥，只感觉别的工具写代码都好像不那么好用……</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2524" >2010/04/18</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @yufeng 呵呵,现在赞同我当时要求你使用VIM了吧. :)</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2527" >2010/04/19</a>, <a href="http://sanmuding.com"  rel="external nofollow"  class="url" >Anders</a> writes: 帮你纠错:

需注意的是，vimpress仅支持xlmrpc，下载前请先检查你的Blog是否具有xlmrpc功能！具体关于xlmrpc的信息请访问http://zh.wikipedia.org/zh-cn/XML-RPC

应该为 xmlrpc吧。</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2528" >2010/04/19</a>, <a href="http://blog.fouland.com/2010/04/vimpress-and-new-colorscheme-of-wp.sb"  rel="external nofollow"  class="url" >SpriteWood &raquo; Blog Archive &raquo; vimpress and new colorscheme of wp</a> writes: [...] google reader, 在 风雪之隅 上发现了这个蛮好玩的东东 vimpress, 配置一下 用户名/密码/xmlrpc地址 [...]</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2530" >2010/04/20</a>, <a href="http://www.js4j.com"  rel="external nofollow"  class="url" >技术世界</a> writes: 我用的不是博客程序!~~</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2555" >2010/05/06</a>, yufeng writes: @雪候鸟 唉，当时要是不用就好了，导致心理失衡，看人家用IDE就想推销VIM，还要用力克制推销欲望，只淡淡一句：哦，其实VIM也挺好用的。</li><li><a href="http://www.laruence.com/2010/04/17/1433.html#comment-2909" >2010/07/12</a>, <a href="http://www.bestfinance-blog.com"  rel="external nofollow"  class="url" >personal loans</a> writes: Do you acknowledge that it is the best time to get the mortgage loans, which will help you.</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/04/17/1433.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Nginx(PHP/fastcgi)的PATH_INFO问题</title>
		<link>http://www.laruence.com/2009/11/13/1138.html</link>
		<comments>http://www.laruence.com/2009/11/13/1138.html#comments</comments>
		<pubDate>Fri, 13 Nov 2009 06:48:15 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[path_info]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1138</guid>
		<description><![CDATA[PATH_INFO是一个CGI 1.1的标准，经常用来做为传参载体.

在Apache中, 当不加配置的时候, 对于PHP脚本, AcceptPathInfo是默认接受的, 也就是说:


如果在服务器在存在一个/laruence/info.php

那么, 对于如下请求, Apache都接受:
<coolcode lang="bash" linenum="off">
/laruence/info.php/dummy
/laruence/info.php/pathinfo
</coolcode>
而对于Nginx下, 默认Nginx是不支持PATH INFO的, 也就是说, 对于上面的访问, 会是404, 提示找不到文件出错.]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/11/13/1138.html"  title="Permanet Link to Nginx(PHP/fastcgi)的PATH_INFO问题" >http://www.laruence.com/2009/11/13/1138.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>PATH_INFO是一个CGI 1.1的标准，经常用来做为传参载体. </p>
<p>比如, 我们可以使用PATH_INFO来代替Rewrite来实现伪静态页面, 另外不少PHP框架也使用PATH_INFO来作为路由载体.</p>
<p>在Apache中, 当不加配置的时候, 对于PHP脚本, AcceptPathInfo是默认接受的, 也就是说:</p>
<p>如果在服务器在存在一个/laruence/index.php</p>
<p>那么, 对于如下请求, </p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
/laruence/index.php/dummy
/laruence/dummy
</pre>
<p>Apache都接受,  都会认为是对info.php的访问, 并会设置PATH_INFO为dummy</p>
<p>而对于Nginx下, 是不支持PATH INFO的, 也就是它不会默认设置PATH_INFO. </p>
<p>而因为默认的配置文件对PHP的支持只是很基础的, 所以对于默认配置来说对于上面的访问也会是404, 提示找不到文件出错.</p>
<p>这对于一些使用PATH_INFO来传递关键信息的PHP框架来说(比如Kohana, Thinkphp), 简直是致命的.</p>
<p>对于这个问题, 一般来说有俩种解决方法, 第一种就是使用rewrite, 但是这个方法的缺点也是很明显的, 需要把PATH_INFO转换成Query String. 此处就不说明这种方法了~</p>
<p>而, 第二种方法就是我今天要提的, 模拟PATH_INFO:</p>
<p>首先 , 我们知道在Nginx中, 是通过对文件名的扩展名匹配, 来决定是否要交给php cgi服务器去解释的. 在nginx.conf中一般都有如下的默认配置段:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
location ~ .php$ {
	fastcgi_index  index.php;
	fastcgi_pass   127.0.0.1:9000;
	include        fastcgi_params;
}
</pre>
<p>所以,对于形如/laruence/info.php/pathinfo这样的文件路径, Nginx是不会正确的交给php cgi服务器的. 所以我们需要改写这段配置为:</p>
<pre name="code"  class="sh_sh"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
	location ~ .php {//片段匹配
	fastcgi_index  index.php;
	fastcgi_pass   127.0.0.1:9000;
	include        fastcgi_params;
}
</pre>
<p>现在, 脚本路径已经交由PHP自己处理了. 那怎么增加PATH_INFO呢?</p>
<p>首先, 我们需要打开PHP中cgi.fix_pathinfo配置项, 打开这个配置项以后, PHP会去根据CGI规范来检查SCRIPT_FILENAME中那部分是访问脚本和PATH_INFO(<a href="http://cn.php.net/manual/en/ini.core.php" >ini配置解释</a>), 并根据SCRIPT_NAME来修改PATH_INFO(和PATH_TRANSLATED)为正确的值(其实也就是说明, PHP最初对CGI 1.1的支持并不到位)</p>
<p>然后, 就只要添加一个FASTCGI_PARAM项就好了:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
location ~ .php {
	fastcgi_index  index.php;
	fastcgi_pass   127.0.0.1:9000;
	include        fastcgi_params;
	fastcgi_param  PATH_INFO $fastcgi_script_name;
}
</pre>
<p>现在试试吧&#8230;</p>
<p>btw: 当然, 上面的解决方法, 把对路径的分析交给了PHP去处理, 网上也有朋友给出了另外一种配置方法, 这个方法是由Nginx来分析路径(也就不需要fix_pathinfo):</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
location ~ \.php
{
	fastcgi_index index.php;
	fastcgi_pass 127.0.0.1:9000;
	include      fastcgi_params;
	set $path_info &quot;&quot;;
	set $real_script_name $fastcgi_script_name;
	if ($fastcgi_script_name ~ &quot;^(.+?\.php)(/.+)$&quot;) {
	set $real_script_name $1;
	set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /var/html/$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
</pre>
<p>    后记, 最近发现的一个安全漏洞(<a href="http://www.laruence.com/2010/05/20/1495.html"  target="_blank" >Nginx + PHP CGI的一个可能的安全漏洞</a>)和这个配置有关系, 请大家务必在使用第二种配置的时候,关闭cgi.fix_pathinfo. 另外关于这个漏洞我个人认为这个和Nginx没啥关系, 不属于Nginx的漏洞. 是配置的问题, 现在到处都在说是Nginx的Bug, 不妥不妥.<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_sh.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2307" >2009/11/13</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: 按上文修改conf后
访问/p.php/
得到的结果是
/p.php/index.php</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2308" >2009/11/13</a>, <a href="http://phpv.net"  rel="external nofollow"  class="url" >esayr</a> writes: 得到的结果
/p.php/index.php

是正常的.相当于一个文件夹.

文章转载请求.:)</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2309" >2009/11/13</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: 纠正下, 我访问/p.php/
PATH_INFO是/index.php
访问/p.php/aa
PATH_INFO是/aa
不明白了</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2310" >2009/11/13</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: @esayr
大概理解你的意思了, 可是问题是apache下访问/p.php/返回的是/
难道只能通过程序去"智能"判断么?
能否通过调整nginx的配置来解决呢?</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2311" >2009/11/14</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @zwws 我已补充自己判断的配置, ;)</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2313" >2009/11/15</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: 反复折腾了三次到现在, 结果依旧如下:

访问http://localhost/p.php/

PATH_INFO 为 /index.php
PHP_SELF 为 /p.php/index.php


配置文件和http://localhost/p.php/的phpinfo()截图放在这了:

http://www.zvv.cn/nginx_conf.rar</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2314" >2009/11/15</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: 有空的话帮忙瞅瞅, thanks. :)</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2315" >2009/11/15</a>, <a href="http://www.zvv.cn"  rel="external nofollow"  class="url" >zwws</a> writes: 解决了.

http://www.zvv.cn/blog/show-110-1.html</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2316" >2009/11/16</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @zwws con~~ ;)</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2321" >2009/11/17</a>, <a href="http://deving.cn"  rel="external nofollow"  class="url" >Torr</a> writes: 好文章，转载到 deving.cn 了，希望可以和更多的人分享</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2438" >2010/01/20</a>, <a href="http://www.laruence.com/2010/01/20/1247.html"  rel="external nofollow"  class="url" >Nginx/PHP Fastcgi PATH_INFO的一个问题 | 风雪之隅</a> writes: [...] 通过在nginx.conf中模拟PATH_INFO的方法会有一个bug. 那就是PATH_INFO不会被urldecode. [...]</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2473" >2010/03/18</a>, <a href="http://www.yibaikuan.com"  rel="external nofollow"  class="url" >xinqiyang</a> writes: 谢谢博主的分享，问题搞定了，Nginx 群</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2495" >2010/04/08</a>, <a href="http://www.lowest-rate-loans.com"  rel="external nofollow"  class="url" >LORIHerrera23</a> writes: I will recommend not to wait until you earn enough money to order different goods! You can get the <a href="http://lowest-rate-loans.com"  rel="nofollow" >loan</a> or just small business loan and feel free</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2599" >2010/05/20</a>, <a href="http://jackywdx.cn/2010/05/path_info_in_php/"  rel="external nofollow"  class="url" >PHP中的PATH_INFO | 鸭嘴的blog</a> writes: [...] Nginx(PHP/fastcgi)的PATH_INFO问题 [...]</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2629" >2010/05/21</a>, <a href="http://www.perday.tv/news/archives/132712"  rel="external nofollow"  class="url" >nginx真的存在文件类型解析漏洞吗？ &laquo; 每日IT新闻，最新IT资讯，聚合多站点消息，保证你与世界同步</a> writes: [...] http://www.laruence.com/2009/11/13/1138.html， [...]</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-2634" >2010/05/22</a>, <a href="http://key0.cn/index.php/archives/730"  rel="external nofollow"  class="url" >nginx文件类型错误解析漏洞 &#8211; kindle&#39;s blog</a> writes: [...] http://www.laruence.com/2009/11/13/1138.html    Posted on 2010-05-21 at 3:05 下午 | Filed: 网络文摘 |  Entry RSS 2.0 feed | Leave a [...]</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-3062" >2010/08/06</a>, <a href="http://www.lampblog.cn/?p=33"  rel="external nofollow"  class="url" >Trail&#39;s Blog &raquo; Nginx(PHP/fastcgi)的PATH_INFO问题</a> writes: [...] 本文地址: http://www.laruence.com/2009/11/13/1138.html [...]</li><li><a href="http://www.laruence.com/2009/11/13/1138.html#comment-3063" >2010/08/06</a>, Guaranteed SEO writes: <a href="http://www.honeypotdigital.co.uk/"  rel="nofollow" >Guaranteed SEO</a> runs a good <a href="http://www.honeypotdigital.co.uk/"  rel="nofollow" >Guaranteed google rank</a> in the 
google.It is made of <a href="http://www.honeypotdigital.co.uk/"  rel="nofollow" >Guaranteed SEO company</a>.Use the guaranteed SEO 
give the customers the guaranteed results whatever you want to search.Customers can put different sort of products in the guaranteed SEO.
Customers can find their products in the <a href="http://www.honeypotdigital.co.uk/"  rel="nofollow" >Guaranteed google results</a>.Guaranteed SEO has a eximious service 
team for every customer to the <a href="http://www.honeypotdigital.co.uk/"  rel="nofollow" >Guaranteed google position</a> to show their products.</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/11/13/1138.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Linux上配置Nginx+PHP5(FastCGI)</title>
		<link>http://www.laruence.com/2009/07/28/1030.html</link>
		<comments>http://www.laruence.com/2009/07/28/1030.html#comments</comments>
		<pubDate>Tue, 28 Jul 2009 09:04:40 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-cgi]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1030</guid>
		<description><![CDATA[Nginx是俄罗斯人编写的十分轻量级的HTTP服务器，以事件驱动的方式编写，所以有非常好的性能，同时也是一个非常高效的反向代理、负载平衡。其拥有匹配Lighttpd的性能，同时还没有Lighttpd的内存泄漏问题，而且Lighttpd的mod_proxy也有一些问题并且很久没有更新。

因此我打算用其替代Apache应用于Linux服务器上。但是Nginx并不支持cgi方式运行，原因是可以减少因此带来的一些程序上的漏洞。那么我们必须使用FastCGI方式来执行PHP程序。

下面是我成功地配置Nginx + PHP5 FastCGI的过程]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>本文地址: <a href="http://www.laruence.com/2009/07/28/1030.html"  title="Permanet Link to Linux上配置Nginx+PHP5(FastCGI)" >http://www.laruence.com/2009/07/28/1030.html</a></li>
<li>转载文章</li>
</ul></div>
<p>
原文地址:http://shiningray.cn/linux-shang-pei-zhi-nginx-php5-fastcgi.html
</p>
<p>
Nginx是俄罗斯人编写的十分轻量级的HTTP服务器，以事件驱动的方式编写，所以有非常好的性能，同时也是一个非常高效的反向代理、负载平衡。其拥有匹配Lighttpd的性能，同时还没有Lighttpd的内存泄漏问题，而且Lighttpd的mod_proxy也有一些问题并且很久没有更新。</p>
<p>因此我打算用其替代Apache应用于Linux服务器上。但是Nginx并不支持cgi方式运行，原因是可以减少因此带来的一些程序上的漏洞。那么我们必须使用FastCGI方式来执行PHP程序。</p>
<p>下面是我成功地配置Nginx + PHP5 FastCGI的过程
</p>
<p><h3>首先安装或编译Nginx</h3>
<p><b>安装Nginx</b</p>
<p>源码包可以在官方主页上下载。Ubuntu 7.10可以直接通过apt安装，也可以从这里下载最新的deb包：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
sudo apt-get install nginx
</pre>
<p>如果要自己编译的话，需要确保自己已经有编译器和PCRE的库(用于Nginx的rewrite模块，如果不需要这个模块可以在configure时使用./configure –without-rewrite),编译方法如下：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
wget http://sysoev.ru/nginx/nginx-0.5.34.tar.gz
tar zxvf nginx-0.5.34.tar.gz
cd nginx-0.5.34
./configure #默认配置安装路径为/usr/local/nginx 可以追加--prefix=/usr设置到/usr
make &amp;&amp; make install  # install要求有root权限
</pre>
<p>Ubuntu安装之后的文件结构大致为：</p>
<p>所有的配置文件都在/etc/nginx下，并且每个虚拟主机已经安排在了/etc/nginx/sites-available下</p>
<p>程序文件在/usr/sbin/nginx</p>
<p>日志放在了/var/log/nginx中</p>
<p>并已经在/etc/init.d/下创建了启动脚本nginx</p>
<p>默认的虚拟主机的目录设置在了/var/www/nginx-default</p>
<p>而自己利用默认配置编译的，则放在/usr/local/nginx下，以下是目录结构：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
/usr/local/nginx/conf 配置目录
/usr/local/nginx/html 默认的网站根目录
/usr/local/nginx/logs 日志和pid文件目录
/usr/local/nginx/sbin 执行文件目录
</pre>
<p>下面可以启动nginx来看看效果（请确保80端口没有其他服务在使用）：<br/>
Ubuntu请运行：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
sudo /etc/init.d/nginx start
</pre>
<p>其他请运行：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
/usr/local/nginx/sbin/nginx
</pre>
<p>然后就可以通过http://localhost/来看看效果了。</p>
<p>要配置nginx的自动运行，可以将/usr/local/nginx/sbin/nginx添加到/etc/rc.local中，Ubuntu可以执行</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
update-rc.d nginx defaults
</pre>
</p>
<p><h3>安装PHP5</h3>
<p>至于如何在Linux上安装PHP，有很多文章，甚至很多平台上都有现成的软件包，无需自己编译。</p>
<p>PHP5的CGI方式的一大优势是内置了FastCGI的支持，只需指明绑定的地址和端口参数便可以以FastCGI的方式运行，如下：</p>
<p>php-cgi -b 127.0.0.1:9000</p>
<p>如何配置其与nginx一起运行呢？</p>
<p><b>配置Nginx的PHP FastCGI</b></p>
<p>请将以下内容保存为fastcgi_params文件，保存于/usr/local/nginx/conf下（Ubuntu可保存于/etc/nginx下），他为我们的FastCGI模块设置了基本的环境变量：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
#fastcgi_params
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
</pre>
<p>请特别注意"fastcgi_script_name"一行，PHP-CGI特别需要此行信息来确定PHP文件的位置。</p>
<p>另外需要在PHP-CGI的配置文件（Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini）中，打开cgi.fix_pathinfo选项：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
cgi.fix_pathinfo=1;
</pre>
<p>这样php-cgi方能正常使用SCRIPT_FILENAME这个变量。</p>
<p>接下来在nginx的配置中针对php文件配置其利用FastCGI进程来执行：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
server {
    index index.php;
    root  /usr/local/nginx/html;

    location ~ .*.php$ {
        include /usr/local/nginx/conf/fastcgi_params;  #请根据自己保存的路径进行设置
        fastcgi_index index.php;
        fastcgi_pass  127.0.0.1:9000; #请根据自己的FastCGI绑定的地址和端口进行配置
    }
}
</pre>
<p>通知Nginx重新载入配置:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
</pre>
<p>Ubuntu用户可以使用init脚本：sudo /etc/init.d/nginx reload</p>
<p>然后启动php-cgi -b 127.0.0.1:9000</p>
<p>假设你在文档根目录放了index.php，并包含"phpinfo();"的内容，现在再看http://localhost/index.php便应该能看到php的调试信息了。</p>
<p><b>配置php进程</b></p>
<p>直接使用php-cgi的FastCGI运行方式有两个问题（貌似应该有解决方案，如果知道的话可以教教我）：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
1.如果进程崩溃，难以配置重新启动
2.单进程的效率低
</pre>
<p>因此，我们可以利用Lighttpd的spawn-fcgi来控制进程的运行。获得spawn-fcgi的方法如下：</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2 #获取Lighttpd的源码包
tar -xvjf lighttpd-1.4.18.tar.bz2
cd lighttpd-1.4.18
./configure  #编译
make
cp src/spawn-fcgi /usr/local/bin/spawn-fcgi #取出spawn-fcgi的程序
</pre>
<p>下面我们就可以使用 spawn-fcgi 来控制php-cgi的FastCGI进程了</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi
</pre>
<p>参数含义如下</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
-f &lt;fcgiapp&gt; 指定调用FastCGI的进程的执行程序位置，根据系统上所装的PHP的情况具体设置
-a &lt;addr&gt; 绑定到地址addr
-p &lt;port&gt; 绑定到端口port
-s &lt;path&gt; 绑定到unix socket的路径path
-C &lt;childs&gt; 指定产生的FastCGI的进程数，默认为5（仅用于PHP）
-P &lt;path&gt; 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份（-u 用户 -g 用户组）运行，Ubuntu下可以使用www-data，其他的根据情况配置，如nobody、apache等
</pre>
<p>然后我们可以将这行代码加入到/etc/rc.local文件底部，这样系统启动的时候也可以同时启动PHP的FastCGI进程。
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2042" >2009/07/28</a>, <a href="http://keyvalue.net"  rel="external nofollow"  class="url" >keyvalue</a> writes: 清晰简约，一贯的风格</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2045" >2009/07/28</a>, xi2008wang writes: 现在都用php-fpm代替spawn-cgi了</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2046" >2009/07/28</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @xi2008wang great, thanks</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2049" >2009/07/29</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 关于配置项, 可以参看:http://wiki.nginx.org/NginxModules</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2112" >2009/07/31</a>, weimade writes: http://php-fpm.org/Main_Page</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2113" >2009/07/31</a>, weimade writes: 手册里也有。。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2114" >2009/08/01</a>, zhangyufeng writes: 前一阵我也搭了一个，感觉最困难的是nginx的rewrite规则……能不能写写这方面……网上很多支离破碎的文章。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2115" >2009/08/01</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: http://wiki.nginx.org/NginxHttpRewriteModule
手册上很详细啊.</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2118" >2009/08/07</a>, zhangyufeng writes: 手册上讲的是如何使用，而我想清楚的是如何用的更好……呵呵，想学习一下前辈的经验。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2216" >2009/09/14</a>, wang writes: 我喜欢用PHP-FPM 给PHP的补丁
使用起来很方便
/usr/local/php5/sbin/php-fpm start
/usr/local/php5/sbin/php-fpm stop
/usr/local/php5/sbin/php-fpm restart</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2424" >2010/01/07</a>, 雀巢 writes: 为什么我在nginx.conf里写入   1. server {
   2.     index index.php;
   3.     root /usr/local/nginx/html;
   4.  
   5.     location ~ .*.php$ {
   6.         include /usr/local/nginx/conf/fastcgi_params; #请根据自己保存的路径进行设置
   7.         fastcgi_index index.php;
   8.         fastcgi_pass 127.0.0.1:9000; #请根据自己的FastCGI绑定的地址和端口进行配置
   9.     }
  10. }

这段话提示错误，无法启动nginx呢？我是在Ubuntu下安装的</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2425" >2010/01/07</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 提示什么错误呢?</li><li><a href="http://www.laruence.com/2009/07/28/1030.html#comment-2478" >2010/03/20</a>, <a href="http://www.toppowerlevel.net"  rel="external nofollow"  class="url" >mybook</a> writes: This guide was written by <a href="http://www.toppowerlevel.net"  rel="nofollow" >wow power leveling</A> Suicidal from the main World of Warcraft community site. It is listed here as it has been an extremely helpful guide. Be sure 
The <a href="http://www.ygscn.net/PowerLevel.php?gid=1"  rel="nofollow" >wow power leveling</A> Warlock can be one of the best damage casters in World of Warcraft, but it's also a very complicated class with its damage-over-time <a href="http://www.toppowerlevel.net/buy.php"  rel="nofollow" >best wow gold</A> (DoT) spells and minions for any occasion. You learn a variety of curses that you will use depending on your situation, and you also gain <a href="http://www.toppowerlevel.net/buy.php"  rel="nofollow" >wow gold uk</A> the ability to send your enemies running away from you in terror. 
Warlocks can be a difficult class to play, but if you can do it well you will be the envy of all other damage <a href="http://www.toppowerlevel.net/buy.php"  rel="nofollow" >cheapest wow gold</A> dealers. Most people will despise you in Player vs Player battles. 
The Warlock can be one of the best damage casters in World of Warcraft, but it's also a very complicated class with its <a href="http://www.toppowerlevel.net/buy.php"  rel="nofollow" >gold for wow</A> damage-over-time (DoT) spells and minions for any occasion. You learn a variety of curses that you will use depending <a href="http://www.toppowerlevel.net"  rel="nofollow" >world of warcraft power leveling</A> on your situation, and you also gain the ability to send your enemies running away from you in terror. Warlocks <a href="http://www.ygscn.net/PowerLevel.php?gid=1"  rel="nofollow" >world of warcraft power leveling</A>
 can be a difficult class to play, but if you can do it well you will be the envy of all other damage dealers. Most people will despise you in Player vs Player battles.</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/07/28/1030.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>phpDocumentor</title>
		<link>http://www.laruence.com/2009/04/21/680.html</link>
		<comments>http://www.laruence.com/2009/04/21/680.html#comments</comments>
		<pubDate>Tue, 21 Apr 2009 08:50:52 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpdoc]]></category>
		<category><![CDATA[phpDocumentor]]></category>
		<category><![CDATA[php编码规范]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=680</guid>
		<description><![CDATA[最近再总结一些PHP的规范, 想起之前在Y!的时候的API描述自动生成工具, 翻到了phpDocumentor, 用起来感觉还是很方便 , 就安装到使用的过程写下来, 与大家分享]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/04/21/680.html"  title="Permanet Link to phpDocumentor" >http://www.laruence.com/2009/04/21/680.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>最近再总结一些PHP的规范, 想起之前在Y!的时候的API描述自动生成工具, 翻到了phpDocumentor, 用起来感觉还是很方便 , 就安装到使用的过程写下来, 与大家分享</p>
<p>phpDocumentor的安装很简单,<br/>
如果通过pear自动安装<br/>
在命令行下输入    pear install PhpDocumentor<br/>
如果是手动安装<br/>
则在http://manual.phpdoc.org/下载最新版本的PhpDocumentor（现在是1.4.2），把内容解压即可.</p>
<p>phpdocumentor的使用也很简单, 分为命令行模式和web模式:</p>
<p>命令行模式<br/>
在phpDocumentor所在目录下，输入<br/>
php –h<br/>
会得到一个详细的参数表，其中几个重要的参数如下：<br/>
-f 要进行分析的文件名，多个文件用逗号隔开<br/>
-d 要分析的目录，多个目录用逗号分割<br/>
-t 生成的文档的存放路径<br/>
-o 输出的文档格式，结构为输出格式：转换器名：模板目录。<br/>
例如：phpdoc -o HTML:frames:earthli -f test.php -t docs</p>
<p>Web模式<br/>
在新的phpdoc中，除了在命令行下生成文档外，还可以在客户端浏览器上操作生成文档，具体方法是先把PhpDocumentor的内容放在 apache目录下使得通过浏览器可以访问到<br/>
点击files按钮，选择要处理的php文件或文件夹，还可以通过该指定该界面下的Files to ignore来忽略对某些文件的处理。<br/>
然后点击output按钮来选择生成文档的存放路径和格式.<br/>
最后点击create，phpdocumentor就会自动开始生成文档了，最下方会显示生成的进度及状态，如果成功，我们就可以通过查看生成的文档了，如果是pdf格式的，名字默认为documentation.pdf。</p>
<p>来看个例子:<br/>
代码加上注释:</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;?php
/**
* @filename baseTags.php
* @touch date Tue 21 Apr 2009 11:49:12 AM CST
* @package phpDocumentor demo
* @author Laruence
* @license http://www.zend.com/license/3_0.txt   PHP License 3.0
* @version 1.0.0
* @copyright (c) 2009, Laruence
*/

/**
* this function is a demo to illustrate how phpdocument tags work
* &lt;code&gt;
* $bool = element(true, &quot;laruence&quot;);
* &lt;/code&gt;
* @deprecated
* @param bool $bool  a flag to decide whether the string should be output
* @param string|int  $string  sometimes it's a string, sometimes it's a int
* @return bool
*/
function element($bool, $string){
if ($bool){
die(&quot;flag off&quot;);
}
echo &quot;I love $string&quot;;
return true;
}
?&gt;</pre>
<p>在命令行模式下输入:<br/>
phpdoc -o HTML:frames:default -f baseTags.php -t docs</p>
<p>还有一些其他技巧, 比如, 你可以把phpdoc这个脚本放到/usr/bin目录下, 将phpdoc.ini和phpdocumentor目录放到php设置的include path 下, 就可以把phpdoc当成shell命令来很方便的使用了. </p>
<p>还有, 比如一些文件的描述信息, 完全可以map成vim的一个宏命令, 我自己就把相关的信息都map成了F12, </p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
function MyCopy()
    call setline(line(&quot;.&quot;),&quot;/**&quot;)
    call append(line(&quot;.&quot;)+1,&quot; * @filename &quot;.expand(&quot;%&quot;))
    call append(line(&quot;.&quot;)+2,&quot; * @touch date &quot;.strftime(&quot;%c&quot;))
    call append(line(&quot;.&quot;)+3,&quot; * @author Laruence&lt;huixinchen@baidu.com&gt;&quot;)
    call append(line(&quot;.&quot;)+4,&quot; * @license http://www.zend.com/license/3_0.txt   PHP License 3.0&quot;)
    call append(line(&quot;.&quot;)+5,&quot; * @version 1.0.0 &quot;)
    call append(line(&quot;.&quot;)+6,&quot;*/&quot;)
endf
map &lt;F12&gt; &lt;Esc&gt;:call MyCopy()&lt;CR&gt;&lt;Esc&gt;5j$a
</pre>
<p>等等.</p>
<p>最后, 生成的API文档见这里: <a href="/docs/"  target="_blank" >例子</a></p>
<p>如果有兴趣, 还可以看看phpdoc的代码, 也是很有意思,呵呵</p>
<p>ps: 相关的tags的说明见phpDocumentor官方网站的说明 <a href="http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.pkg.html"  target="_blank" >tags说明手册</a><br/>
<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-1612" >2009/04/21</a>, <a href="http://syre.blogbus.com"  rel="external nofollow"  class="url" >神仙</a> writes: 之前的phpdoc的代码实在是乱七八糟。
现在的phpDocumentor好多了</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-1613" >2009/04/21</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 你很快~</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-1614" >2009/04/21</a>, zhangYufeng writes: 收藏，呵呵。</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-1615" >2009/04/21</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 你刚才说的那个问题, 如果没有文件级注释, 第一个注释会误认为是第一个函数定义的注释, 我想了下, 文件级注释的tag和函数的注释tag应该是不一样的..</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-3119" >2010/08/26</a>, Ssfds writes: sfdsfdsfd</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-3120" >2010/08/26</a>, www writes: available that are hand crafted with <a href="http://www.shinewigs.com/clearance_wigs-hair_wigs.html"  rel="nofollow" >full lace wigs</a> hide their balding heads <a href="http://www.shinewigs.com/"  rel="nofollow" >lace wigs</a> hair extension salons real human hair extensions <a href="http://www.shinewigs.com/"  rel="nofollow" >lace wig</a> short or long?? there are <a href="http://www.beautwigs.com/"  rel="nofollow" >wigs</a> afro wigs remi human hair <a href="http://www.basicwigs.com/monthly_specials-classic-hair_wigs.html"  rel="nofollow" >hannah montana wig</a> versatile Similar to real <a href="http://www.beautwigs.com/"  rel="nofollow" >lace front wigs</a> clip on hair extensions Here is one of the best sites that <a href="http://www.basicwigs.com/monthly_specials-classic-hair_wigs.html"  rel="nofollow" >hannah montana wigs</a> have the advantage of a put on pieces hair extensions <a href="http://www.beautwigs.com/"  rel="nofollow" >human hair wigs</a> lacefront wig It is a good idea to have your wigs <a href="http://www.shinewigs.com/clearance_wigs-hair_wigs.html"  rel="nofollow" >human hair</a> hair wig It is easier to <a href="http://www.shinewigs.com/"  rel="nofollow" >full lace wigs</a> premium lace wigs can cost several hundred dollars Its <a href="http://www.basicwigs.com/human_hair_wigs-hair_wigs.html"  rel="nofollow" >remi lace wigs</a> near heat sources with this kind of albert einstein costume <a href="http://www.shinewigs.com/human_hair_wigs-hair_wigs.html"  rel="nofollow" >remi human hair</a> of having a bald head or receding.</li><li><a href="http://www.laruence.com/2009/04/21/680.html#comment-3171" >2010/09/08</a>, Eric writes: 不错，学习了，可惜我们公司的代码注释的不太规范，无法生成文档了。。。</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/04/21/680.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP5多层继承顺序的bug</title>
		<link>http://www.laruence.com/2008/08/24/427.html</link>
		<comments>http://www.laruence.com/2008/08/24/427.html#comments</comments>
		<pubDate>Sun, 24 Aug 2008 13:43:57 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP源码分析]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=427</guid>
		<description><![CDATA[<p>今天guoxiaod提出了一个问题，如下：
  <coolcode lang="php" linenum="off">
<?php
class a extends b {
};
class b extends c{
};
class c{
};
?>
  </coolcode>
 会导致fatal error:
<coolcode lang="shell" linenum="off">
PHP Fatal error:  Class 'b' not found in /home/xinchen/1.php on line 2
Fatal error: Class 'b' not found in /home/xinchen/1.php on line 2
</coolcode>
 分析这个问题，是运行阶段出错，经过分析PHP的编译，执行过程，得出如下的parsing顺序...</p>]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/08/24/427.html"  title="Permanet Link to PHP5多层继承顺序的bug" >http://www.laruence.com/2008/08/24/427.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>今天guoxiaod提出了一个问题，如下：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;?php
class a extends b {
};
class b extends c{
};
class c{
};
?&gt;
  </pre>
<p> 会导致fatal error:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
PHP Fatal error:  Class 'b' not found in /home/xinchen/1.php on line 2
Fatal error: Class 'b' not found in /home/xinchen/1.php on line 2
</pre>
<p>分析这个问题，是运行阶段出错，经过分析PHP的编译，执行过程，得出如下的parsing顺序…</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
start:
    top_statement_list
;

top_statement_list:
        top_statement_list
.... //有省略
;

top_statement:
.... //有省略
    |   class_declaration_statement
 .... //有省略
;

class_declaration_statement:
        unticked_class_declaration_statement
;

unticked_class_declaration_statement:
        class_entry_type T_STRING extends_from
.... //有省略
;

class_entry_type:
        T_CLASS
.... //有省略
;

extends_from:
        /* empty */
    |   T_EXTENDS fully_qualified_class_name
.... //有省略
;
fully_qualified_class_name:
        T_STRING { zend_do_fetch_class(&amp;$$, &amp;$1 TSRMLS_CC); }
;
</pre>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
zend_do_fetch_class 会设置opcode = ZEND_FETCH_CLASS
</pre>
<p>从这个过程我们可以发现，这个应该是PHP5的bug， 对于fully_qualified_class_name，如果fully_qualified_class_name也是继承来自一个类，那么就会出错， 因为fully_qualified_class_name只是简单的去fetch_class, 而如果这个时候，这个类还没有被填入到class_table就会出错。也就是说，需要有个机制，来保证父class首先被处理。</p>
<p>以下是我分析源码后的结论：<br/>
对于a，因为是个派生类，在编译阶段，当遇到它的定义的时候，会：</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
 zend_do_begin_class_declaration
</pre>
<p>在这个函数中，会调用:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
 build_runtime_defined_function_key(&amp;opline-&gt;op1.u.constant, lcname, name_len TSRMLS_CC);
</pre>
<p>来产生一个：</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
   sprintf(result-&gt;value.str.val, &quot;%c%s%s%s&quot;, '\0', name, filename, char_pos_buf);
</pre>
<p>的字符串，来做为一个编译器的classname存入class_table:</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
    zend_hash_update(CG(class_table), opline-&gt;op1.u.constant.value.str.val, opline-&gt;op1.u.constant.value.str.len, &amp;new_class_entry, sizeof(zend_class_entry *), NULL);
</pre>
<p>最后在吸收top_statement的时候，会有一次类的生成(填入class_table);</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
top_statement:
        statement
 ...
    |   class_declaration_statement     { zend_do_early_binding(TSRMLS_C); }
...
...
;
</pre>
<p>在zend_do_early_binding的时候：</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
void zend_do_early_binding(TSRMLS_D){
...
...
  switch (opline-&gt;opcode) {
      case ZEND_DECLARE_FUNCTION:
          if (do_bind_function(opline, CG(function_table), 1) == FAILURE) {
              return;
          }
          table = CG(function_table);
          break;
      case ZEND_DECLARE_CLASS:
      case ZEND_DECLARE_INHERITED_CLASS:
          is_abstract_class = 1;
          /* break missing intentionally */
      case ZEND_VERIFY_ABSTRACT_CLASS: {
              zend_op *verify_abstract_class_op = opline;

              if (!is_abstract_class) {
                  opline--;
              }
              if (opline-&gt;opcode == ZEND_DECLARE_CLASS) {
                  if (do_bind_class(opline, CG(class_table), 1 TSRMLS_CC) == NULL) {
                      return;
                  }
              } else if (opline-&gt;opcode == ZEND_DECLARE_INHERITED_CLASS) {
                  zval *parent_name = &amp;(opline-1)-&gt;op2.u.constant;
                  zend_class_entry **pce;

                    if (zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &amp;pce TSR
MLS_CC) == FAILURE) {
                        return;
                    }
                    if (do_bind_inherited_class(opline, CG(class_table), *pce, 1 TSRMLS_CC) == NULL)
 {
                        return;
                    }
                    /* clear unnecessary ZEND_FETCH_CLASS opcode */
}
</pre>
<p>看到了吧，如果找不到父类，就直接返回了，也就是说，派生类在编译期如果找不到父类，就不会被真正初始化，而是推迟到执行期。会分配一个opcode为ZEND_DECLARE_INHERITED_CLASS的opline，用来在运行期真正生成定义的类：</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
ZEND_API zend_class_entry *do_bind_inherited_class(zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time TSRMLS_DC)
{
.......
//hash_merg子类和父类的属性、方法
    if (zend_hash_add(class_table, opline-&gt;op2.u.constant.value.str.val, opline-&gt;op2.u.constant.value.str.len+1, pce, sizeof(zend_class_entry *), NULL)==FAILURE)
.....
}
</pre>
<p>这个时候问题就来了：<br/>
因为我们的b也是一个派生类，所以在执行a的do_bind_inherited_class时候，对于b，他也需要做一个ZEND_DECLARE_INHERITED_CLASS，也就是说，此时的class_table中是没有b的。<br/>
这也就解释了，如果最基类c，定义在前的时候，就不会出错。</p>
<p>恩，这个应该是PHP5的一个Bug。 </p>
<p>我已经报bug给PHP开发组并发信询问Rasmus Lerdof(the creator of PHP)，看他们怎么说了：<br/>
<a href="http://bugs.php.net/bug.php?id=45904" >http://bugs.php.net/bug.php?id=45904</a>
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-88" >2008/08/24</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >guoxiaod</a> writes: 不过，按照这个逻辑的话，似乎就是这么设计的。</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-89" >2008/08/24</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >guoxiaod</a> writes: 给 rasmus 发个信 ?</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-90" >2008/08/24</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 报了bug了，看看PHP开发组怎么回应吧。</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-97" >2008/08/25</a>, <a href="http://onemouse.cn"  rel="external nofollow"  class="url" >guoxiaod</a> writes: 这样似乎可以想的通
bind 的时候只有 c 是存在的
执行的时候 自然找不到 b
而 如果c 在前的话 ， b 就bind 了
自然 b就可以找到了</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-98" >2008/08/25</a>, <a href="http://www.surfchen.org"  rel="external nofollow"  class="url" >surfchen</a> writes: 这个bug有人报过。http://bugs.php.net/bug.php?id=6418</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-99" >2008/08/25</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 哦？看到了，他是针对PHP4， 另外也没关系，起码我们分析出原因了。
也就明白了，为什么单层继承不会出问题。
并且，对于上例，如果c定义在前，也不会出问题。</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-103" >2008/08/26</a>, chinawolfs writes: 
执行这样应该不会有什么问题的.顺序的情况</li><li><a href="http://www.laruence.com/2008/08/24/427.html#comment-144" >2008/09/08</a>, x writes: [25 Aug 9:13am UTC] tularis@php.net 
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of bug #45903</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/08/24/427.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>深入浅出PHP(Exploring PHP)</title>
		<link>http://www.laruence.com/2008/08/11/147.html</link>
		<comments>http://www.laruence.com/2008/08/11/147.html#comments</comments>
		<pubDate>Mon, 11 Aug 2008 12:48:43 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP源码分析]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend/PHP]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=147</guid>
		<description><![CDATA[横观国内的PHP现状，一直以来，很少有专门介绍PHP内部机制的书。
对于Zend引擎，PHP扩展开发等相关的知识，中文资料很少。
呵呵，鉴于此：
我会随时记录下研究的心得，希望有机会的时候，可以汇总成书。:)]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/08/11/147.html"  title="Permanet Link to 深入浅出PHP(Exploring PHP)" >http://www.laruence.com/2008/08/11/147.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>一直以来，横观国内的PHP现状，很少有专门介绍PHP内部机制的书。呵呵，我会随时记录下研究的心得，有机会的时候，汇总成书。:)</p>
<p>今天这篇，我内心是想打算做为一个导论：</p>
<p>PHP是一个被广泛应用的脚本语言，因为它的成功，所以很多时候，我们应用PHP的时候是更不不需要考虑底层到底是怎么实现的。我相信大多数的PHP程序 员是不会去考虑这一点的。从我接触PHP开始，到今天也就是3年，这三年里，前俩年我一直都是在&#8221;用&#8221;PHP，每次写出来一段脚本，我就会想“恩，不用担 心，PHP解释器会知道我想做什么的”，直到去年来到雅虎，接受了一个工作，是做一个PHP的Extension，从这个时候开始，我就好奇于新接触的一 大堆的新鲜事物，zend, TSRM, zval, hashtable, op_array…</p>
<p>于是我到处查阅资料，每次获得一篇好的文章，或者一段好的文字我就会如获珍宝，打印保存起来，细细研读。我发现，国内关于PHP内部的资料真是少的可怜， 不知道是因为懂得的人多但是不愿意分享，还是懂得的人本来就少，所以，这条路，我走的很辛苦。于是，就会有了这篇文章。</p>
<p>在这篇文章中，我会从整个PHP的执行期入手，大致的介绍下各个阶段，词法分析，语法分析，op code等等，以后的文章我会再详细介绍每个阶(当然，如果你急不可耐的想知道详细，呵呵，那么可以直接联系我)。</p>
<p>从最初我们编写的PHP脚本-&gt;到最后脚本被执行-&gt;得到执行结果，这个过程，其实可以分为如下几个阶段（鄙视：CSDN不能上图）：</p>
<p>首先，Zend Engine(ZE)，调用词法分析器(Lex生成的，源文件在 Zend/zend_language_sanner.l), 将我们要执行的PHP源文件，去掉空格 ，注释，分割成一个一个的token。</p>
<p>然后，ZE会将得到的token forward给语法分析器(yacc生成, 源文件在 Zend/zend_language_parser.y)，生成一个一个的op code，opcode一般会以op array的形式存在，它是PHP执行的中间语言。</p>
<p>最后，ZE调用zend_executor来执行op array，输出结果。<br/>
   <center><a href="http://www.laruence.com/wp-content/uploads/zend_engine.png" ><img src="http://www.laruence.com/wp-content/uploads/zend_engine-300x276.png"  alt=""  title="zend_engine"  width="300"  height="276"  class="alignnone size-medium wp-image-154" /></a></center><br/>
                                      <center>图1 处理流程</center><br/>
ZE是一个虚拟机，正是由于它的存在，所以才能使得我们写PHP脚本，完全不需要考虑所在的操作系统类型是什么。ZE是一个CISC（复杂指令处理器）， 它支持150条指令（具体指令在 Zend/zend_vm_opcodes.h），包括从最简单的ZEND_ECHO(echo)到复杂的 ZEND_INCLUDE_OR_EVAL(include,require)，所有我们编写的PHP都会最终被处理为这150条指令(op code)的序列，从而最终被执行。</p>
<p>那有什么办法可以看到我们的PHP脚本，最终被“翻译”成什么样的呢？ 也就是说，op code张的什么样子呢？ 呵呵，达到这个，我们需要重新编译PHP，修改它的compile_file和zend_execute函数。不过，在PECL中已经有这样的模块，可以 让我们直接使用了，那就是由 Derick Rethans开发的VLD (Vulcan Logic Dissassembler)模块。你只要下载这个模块，并把他载入PHP中，就可以通过简单的设置，来得到脚本翻译的结果了。具体关于这个模块的使用说 明－雅虎一下，你就知道^_^。</p>
<p>接下来，让我们尝试用VLD来查看一段简单的PHP脚本的中间语言。</p>
<p>原始代码：</p>
<div class="hl-surround" >
<div class="hl-main" ><span style="color: blue;" >&lt;?php</span><span style="color: gray;" ></p>
<p></span><span style="color: #00008b;" >$i</span><span style="color: gray;" > = </span><span style="color: #8b0000;" >&#8220;</span><span style="color: red;" >This is a string</span><span style="color: #8b0000;" >&#8220;</span><span style="color: gray;" >;</p>
<p></span><span style="color: #ffa500;" >//I am comments</span><span style="color: gray;" ></p>
<p></span><span style="color: green;" >echo</span><span style="color: gray;" > </span><span style="color: #00008b;" >$i</span><span style="color: gray;" >.</span><span style="color: #8b0000;" >‘</span><span style="color: red;" > that has been echoed to screen</span><span style="color: #8b0000;" >‘</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >?&gt;</span></div>
</div>
<p>采用VLD得到的op codes:</p>
<div class="hl-surround" >
<div class="hl-main" ><span style="color: blue;" > filename</span><span style="color: gray;" >:/</span><span style="color: blue;" >home</span><span style="color: gray;" >/</span><span style="color: blue;" >Desktop</span><span style="color: gray;" >/</span><span style="color: blue;" >vldOutOne</span><span style="color: gray;" >.</span><span style="color: blue;" >php</span><span style="color: gray;" ></p>
<p></span><span style="font-family: Courier New;" ><span style="color: gray;" > </span><span style="color: green;" >function</span><span style="color: gray;" > </span><span style="color: blue;" >name</span><span style="color: gray;" >: </span><span style="color: olive;" >(</span><span style="color: green;" >null</span><span style="color: olive;" >)</span><span style="color: gray;" ></p>
<p></span><span style="color: blue;" >number</span><span style="color: gray;" > </span><span style="color: blue;" >of</span><span style="color: gray;" > </span><span style="color: blue;" >ops</span><span style="color: gray;" >: </span><span style="color: maroon;" >7</span><span style="color: gray;" ></p>
<p></span><span style="color: blue;" >line</span><span style="color: gray;" > </span><span style="color: #ffa500;" >#  op                 fetch       ext  operands</span><span style="color: gray;" ></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p></span><span style="color: maroon;" >2</span><span style="color: gray;" > </span><span style="color: maroon;" >0</span><span style="color: gray;" > </span><span style="color: blue;" >FETCH_W</span><span style="color: gray;" > </span><span style="color: blue;" >local</span><span style="color: gray;" > $</span><span style="color: maroon;" >0</span><span style="color: gray;" >, </span><span style="color: #8b0000;" >&#8216;</span><span style="color: red;" >i</span><span style="color: #8b0000;" >&#8216;</span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >1</span><span style="color: gray;" > </span><span style="color: blue;" >ASSIGN</span><span style="color: gray;" > $</span><span style="color: maroon;" >0</span><span style="color: gray;" >, </span><span style="color: #8b0000;" >&#8216;</span><span style="color: red;" >This+is+a+string</span><span style="color: #8b0000;" >&#8216;</span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >4</span><span style="color: gray;" > </span><span style="color: maroon;" >2</span><span style="color: gray;" > </span><span style="color: blue;" >FETCH_R</span><span style="color: gray;" > </span><span style="color: blue;" >local</span><span style="color: gray;" > $</span><span style="color: maroon;" >2</span><span style="color: gray;" >, </span><span style="color: #8b0000;" >&#8216;</span><span style="color: red;" >i</span><span style="color: #8b0000;" >&#8216;</span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >3</span><span style="color: gray;" > </span><span style="color: blue;" >CONCAT</span><span style="color: gray;" > ~</span><span style="color: maroon;" >3</span><span style="color: gray;" >, $</span><span style="color: maroon;" >2</span><span style="color: gray;" >,</span></span><span style="font-family: Courier New;" ><span style="color: #8b0000;" >&#8216;</span><span style="color: red;" >+that+has+been+echoed+to+screen</span><span style="color: #8b0000;" >&#8216;</span></span><span style="font-family: Courier New;" ><span style="color: gray;" > </span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >4</span><span style="color: gray;" > </span><span style="color: green;" >ECHO</span><span style="color: gray;" > ~</span><span style="color: maroon;" >3</span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >6</span><span style="color: gray;" > </span><span style="color: maroon;" >5</span><span style="color: gray;" > </span><span style="color: green;" >RETURN</span><span style="color: gray;" > </span><span style="color: maroon;" >1</span><span style="color: gray;" ></p>
<p></span><span style="color: maroon;" >6</span><span style="color: gray;" > </span><span style="color: blue;" >ZEND_HANDLE_EXCEPTION</span></span></div>
</div>
<p>我们可以看到，源文件中的注释，在op code中，已经没有了，所以不用担心注释太多会影响你的脚本执行时间（实际上，它是会影响ZE的词法处理阶段的用时而已）。</p>
<p>现在我们来一条一条的分析这段op codes，每一条op code 又叫做一条op_line，都由如下7个部分，在zend_compile.h中，我们可以看到如下定义：</p>
<div class="hl-surround" >
<div class="hl-main"  style="margin-left: 40px;" ><span class="hl-types" >struct</span><span style="color: gray;" > </span><span style="color: blue;" >_zend_op</span><span style="color: gray;" > </span><span style="color: olive;" >{</span><span style="color: gray;" ></p>
<p></span><span style="color: blue;" >opcode_handler_t</span><span style="color: gray;" > </span><span style="color: blue;" >handler</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >znode</span><span style="color: gray;" > </span><span style="color: blue;" >result</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >znode</span><span style="color: gray;" > </span><span style="color: blue;" >op1</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >znode</span><span style="color: gray;" > </span><span style="color: blue;" >op2</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >ulong</span><span style="color: gray;" > </span><span style="color: blue;" >extended_value</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >uint</span><span style="color: gray;" > </span><span style="color: blue;" >lineno</span><span style="color: gray;" >;</p>
<p></span><span style="color: blue;" >zend_uchar</span><span style="color: gray;" > </span><span style="color: blue;" >opcode</span><span style="color: gray;" >;</p>
<p></span><span style="color: olive;" >}</span><span style="color: gray;" >;</span></div>
</div>
<p>其中，opcode字段指明了这操作类型，handler指明了处理器，然后有俩个操作数，和一个操作结果。</p>
<ol>
<li>FETCH_W, 是以写的方式获取一个变量，此处是获取变量名”i”的变量于$0（*zval）。</li>
<li>将字符串”this+is+a+string”赋值(ASSIGN)给$0</li>
<li>字符串连接</li>
<li>显示</li>
</ol>
<p>可以看出，这个很类似于很多同学大学学习编译原理时候的三元式，不同的是，这些中间代码会被Zend VM（Zend虚拟机）直接执行。</p>
<p>真正负责执行的函数是，zend_execute, 查看zend_execute.h:</p>
<pre name="code"  class="sh_cpp"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
ZEND_API extern void (*zend_execute)(zend_op_array *op_array TSRMLS_DC);
</pre>
<p>可以看出， zend_execute接受zend_op_array*作为参数。 </p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
 struct _zend_op_array {
    /* Common elements */
    zend_uchar type;
    char *function_name;
    zend_class_entry *scope;
    zend_uint fn_flags;
    union _zend_function *prototype;
    zend_uint num_args;
    zend_uint required_num_args;
    zend_arg_info *arg_info;
    zend_bool pass_rest_by_reference;
    unsigned char return_reference;
    /* END of common elements */

    zend_uint *refcount;

    zend_op *opcodes;
    zend_uint last, size;

    zend_compiled_variable *vars;
    int last_var, size_var;

    zend_uint T;

    zend_brk_cont_element *brk_cont_array;
    zend_uint last_brk_cont;
    zend_uint current_brk_cont;

    zend_try_catch_element *try_catch_array;
    int last_try_catch;

    /* static variables support */
    HashTable *static_variables;

    zend_op *start_op;
    int backpatch_count;

    zend_bool done_pass_two;
    zend_bool uses_this;

    char *filename;
    zend_uint line_start;
    zend_uint line_end;
    char *doc_comment;
    zend_uint doc_comment_len;

    void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};
</pre>
<p>可以看到，zend_op_array的结构和zend_function的结构很像（参看我的其他文章）， 对于在全局作用域的代码，就是不包含在任何function内的op_array,它的function_name为NULL。结构中的opcodes保存了属于这个op_array的op code数组，zend_execute会从start_op开始，逐条解释执行传入的每条op code, 从而实现我们PHP脚本想要的结果。
</p>
<p> 下一次，我将介绍PHP变量的灵魂 &#8211; zval, 你将会看到PHP是如何实现它的变量传递，类型戏法，等等。<br/>
<script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_cpp.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-13" >2008/08/11</a>, <a href="http://www.apear.cn"  rel="external nofollow"  class="url" >xinquan</a> writes: en, not bad ... continue ...</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-14" >2008/08/11</a>, <a href="http://icyriver.net"  rel="external nofollow"  class="url" >冰的河</a> writes: 不错，尤其是右手代码，左手诗，很赞。要坚持，俗话说：一个人，吟一首诗并不难；难的是，吟一辈子诗。</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-15" >2008/08/12</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩，有功夫我就写点，呵呵；）</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-22" >2008/08/13</a>, yongtao.pang writes: 看zval去啦，有人劈荆斩棘真好</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-38" >2008/08/18</a>, <a href="http://www.lffly.com"  rel="external nofollow"  class="url" >lffly</a> writes: 写的不错。订阅了你的博客</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-59" >2008/08/21</a>, <a href="http://blog.csdn.net/ylcz"  rel="external nofollow"  class="url" >ylcz</a> writes: 太深奥了</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-72" >2008/08/23</a>, Leftwater writes: 决定长期阅读学习博主文章~</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-82" >2008/08/24</a>, liexusong writes: 你出PHP内核的书的话，我一定买！！</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-101" >2008/08/25</a>, <a href="http://glemir.xplore.cn"  rel="external nofollow"  class="url" >glemir</a> writes: 冰之河说：“要坚持，俗话说：一个人，吟一首诗并不难；难的是，吟一辈子诗”
xinquan的目标是要吟一辈子“唐诗”。</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-142" >2008/09/08</a>, sue writes: 传说中的“右手诗”在哪里啊。。</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-216" >2008/10/13</a>, highjade writes: 学习~</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-361" >2008/11/20</a>, <a href="http://www.yvdeo.com"  rel="external nofollow"  class="url" >smilesoul</a> writes: 老大啊  你是我的偶像啊   你怎么学这么深  佩服佩服！

能不能指点下怎么学写一个php的c扩展

需要具备学习哪些知识，能不能谈谈经验</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-428" >2008/12/07</a>, guangtianxia writes: 支持这种精神。</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-1617" >2009/04/22</a>, <a href="http://www.self-trust.cn"  rel="external nofollow"  class="url" >coolboy0316</a> writes: 太深奥了，不是很懂.
学习....</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-1672" >2009/05/06</a>, <a href="http://www.coudou.com"  rel="external nofollow"  class="url" >dyh1919</a> writes: 编译原理没学好，看不懂</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-1787" >2009/05/30</a>, <a href="http://52037872.cn"  rel="external nofollow"  class="url" >不是什么区</a> writes: 不错，既然有现成了我就懒得写了，不介意我转走了吧？</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2256" >2009/10/09</a>, <a href="http://no"  rel="external nofollow"  class="url" >zhifu</a> writes: 强人，我也做了快一年的PHPER，最近在写项目，总是遇到很棘手的问题，导致最后学得去研究底层，现在才发现，要想把技术做好，真得研究底层。

还是很感谢，楼主有这样的精力去研究，并开源给我们，小弟真的十分感谢呀</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2451" >2010/02/01</a>, <a href="http://www.phpfamily.cn"  rel="external nofollow"  class="url" >xiaokai</a> writes: 很是深奥, 但是总一天我会弄懂的..</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2573" >2010/05/15</a>, phper writes: 博主的文章写得太好了！偶像,我要长期关注</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2692" >2010/05/28</a>, 人海孤鸿 writes: 赞</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2972" >2010/07/23</a>, <a href="http://www.commentset.com"  rel="external nofollow"  class="url" >mahone</a> writes: 非常可惜啊，不是计算机专业，编译原理和汇编都没学过……悲剧啊……看不懂文章</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-2973" >2010/07/23</a>, <a href="http://www.commentset.com"  rel="external nofollow"  class="url" >mahone</a> writes: 不是计算机专业，没学过编译原理和汇编，看不懂文章……可悲……</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-3006" >2010/07/29</a>, <a href="http://www.g.cn"  rel="external nofollow"  class="url" >google</a> writes: 翻山越岭终于找到这篇好文章</li><li><a href="http://www.laruence.com/2008/08/11/147.html#comment-3117" >2010/08/26</a>, xiaobao writes: 上面那张图对吗，鸟哥？
require或者函数是编译的时候一并编译了，还是等到执行的时候，再回头去编译？好像应该是前者吧。</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/08/11/147.html/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Apache启动过程(PHP_MINIT_FUNCTION的调用)</title>
		<link>http://www.laruence.com/2008/07/24/206.html</link>
		<comments>http://www.laruence.com/2008/07/24/206.html#comments</comments>
		<pubDate>Thu, 24 Jul 2008 06:36:45 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP源码分析]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=206</guid>
		<description><![CDATA[一封通信记录。关于Apache的启动过程的分析。]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/07/24/206.html"  title="Permanet Link to Apache启动过程(PHP_MINIT_FUNCTION的调用)" >http://www.laruence.com/2008/07/24/206.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>信件内容，to eng-all;<br/>
Hi  all:<br/>
   上次我做的讲座中，讲到，PHP模块的MINIT_FUNCTION在多进程的环境下，会被调用多次，也就是，每个apache的自进程都会去调用一次。<br/>
      今天早上的时候，学鹏经过实际验证发现事实不是这样。<br/>
      于是经过反复验证 ，终于得出如下结论：<br/>
      当Apache启动的时候，主进程会首先把所有模块load进来，然后又卸载掉 他们，这是第一遍，目的是为了检查配置文件。如果一切正常，Apache就会重新 load一便所有的模块，然后才fork子进程，这样，PHP模块就会只被初始化一次， 然后在fork的时候复制给子进程。<br/>
      当apache关闭的时候 ，每个自进程都会去调用一次模块的关闭函数。 </p>
<p>   也就是说， PHP模块的初始化函数只会被调用一次，而关闭函数会被调用多次。 </p>
<p>   猜想是因为apache1.5x以后，做了优化，造成现在的这种机制，apache1.3应 该还是和我当时讲的一样。<br/>
   最后，非常感谢学鹏的实际验证，没有实际验证，这个问题就不会被发现。<br/>
   真正要了解一个东西，不应该只是听听就算，应该去动手验证一下，再次对学 鹏师兄表示，赞！ </p>
<div class="Section1"  style="layout-grid:15.6pt" >
<p class="MsoNormal" ><span lang="EN-US"  style="font-size:8.5pt;font-family:"Arial Unicode MS","sans-serif";color:#76238E" ><img width="34"  height="21"  src="http://farm4.static.flickr.com/3169/2702426257_f41b77149c.jpg?v=0"  alt="Yahoo" /></span><span style="font-size:9.0pt;font-family:"Batang","serif";color:#76238E" >惠新宸<span lang="EN-US" > xinchen.hui</span></span><b><span lang="EN-US"  style="font-size:9.0pt;font-family:"Batang","serif"" > <span style="color:gray" >| </span</span></b><span lang="EN-US"  style="font-size:9.0pt;font-family:"Batang","serif";color:gray" >Engineer<b>| </b>+86 659-86111 <b>|</b> Y! China</span></p>
</div>
<hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/07/24/206.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用C++编写Apache的模块 &#8212; 命令表,保存配置信息</title>
		<link>http://www.laruence.com/2008/04/09/112.html</link>
		<comments>http://www.laruence.com/2008/04/09/112.html#comments</comments>
		<pubDate>Tue, 08 Apr 2008 16:56:21 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[GNU C/C++]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Module]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=112</guid>
		<description><![CDATA[    还是和论文相关，要编写一个Apache的模块，挂在post read_request阶段，在第一时间，判断一个链接是否是而已连接请求，并在第一时间拒绝恶意连接请求。
      首先遇到的第一个问题，就是需要从http.conf中读取配置信息，提供俩个配置指令，MaxNumber, TimeRange.指定在一段时间内的连接次数上限。
       编写的时候，遇到的第一个问题就是，moudule申明，不能通过编译，编译器提示重复定义。查了N遍手边的apache源码分析，也没有找到原因,如： ........
      ]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2008/04/09/112.html"  title="Permanet Link to 使用C++编写Apache的模块 &#8212; 命令表,保存配置信息" >http://www.laruence.com/2008/04/09/112.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 还是和论文相关，要编写一个Apache的模块，挂在post read_request阶段，在第一时间，判断一个链接是否是而已连接请求，并在第一时间拒绝恶意连接请求。<br/>
&nbsp;&nbsp;&nbsp; &nbsp; 首先遇到的第一个问题，就是需要从http.conf中读取配置信息，提供俩个配置指令，MaxNumber, TimeRange.指定在一段时间内的连接次数上限。<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 编写的时候，遇到的第一个问题就是，moudule申明，不能通过编译，编译器提示重复定义。查了N遍手边的apache源码分析，也没有找到原因,如：<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><span style="color: rgb(0, 0, 0);" >&#8230;&#8230;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" />module&nbsp;door_module;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" />&#8230;&#8230;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_76_394_Open_Text').style.display='none'; document.getElementById('_76_394_Closed_Image').style.display='inline'; document.getElementById('_76_394_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_76_394_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_76_394_Closed_Text').style.display='none'; document.getElementById('_76_394_Open_Image').style.display='inline'; document.getElementById('_76_394_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_76_394_Closed_Image"  alt="" />module&nbsp;MODULE_VAR_EXPORT&nbsp;door_module&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_76_394_Closed_Text" >&#8230;</span><span id="_76_394_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STANDARD_MODULE_STUFF,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create_door_config,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;door_cmds,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;door_authorization,<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" >;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /></span></div>
</div>
<p>&nbsp;</p>
<p>&nbsp;最后，删除掉第一个module申明， 通过编译。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  遇到的第二个问题，就是命令表中的命令处理函数在http_config.h中的定义如下:</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;(</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cmd_func)();</span></div>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 但是，《Aapache源码分析》和网上的资料中，命令处理都是带有参数的，如下：</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;maxRequest(cmd_parms&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cmd,&nbsp;</span><span style="color: rgb(0, 0, 255);" >void</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;dconf,&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;arg);</span></div>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 真是，奇怪的很，我使用的是Apache 1.3的dev包，不知道是不是因为版本太低的缘故？ 最后，修改了http_config.h， 通过编译，并且工作正常。真的很奇怪，留待以后解决。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp; 这俩个问题这么糊涂的解决以后，接下来的工作就很简单了。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 首先在server config阶段，初始化我们的全局配置结构。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  onclick="this.style.display='none'; document.getElementById('_15_61_Open_Text').style.display='none'; document.getElementById('_15_61_Closed_Image').style.display='inline'; document.getElementById('_15_61_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_15_61_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_15_61_Closed_Text').style.display='none'; document.getElementById('_15_61_Open_Image').style.display='inline'; document.getElementById('_15_61_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_15_61_Closed_Image"  alt="" /><span style="color: rgb(0, 0, 0);" >typedef&nbsp;</span><span style="color: rgb(0, 0, 255);" >struct</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_15_61_Closed_Text" >&#8230;</span><span id="_15_61_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >int</span><span style="color: rgb(0, 0, 0);" >&nbsp;MaxNumber;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >int</span><span style="color: rgb(0, 0, 0);" >&nbsp;TimeLimit;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" >mod_door_config;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /><br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_137_317_Open_Text').style.display='none'; document.getElementById('_137_317_Closed_Image').style.display='inline'; document.getElementById('_137_317_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_137_317_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_137_317_Closed_Text').style.display='none'; document.getElementById('_137_317_Open_Image').style.display='inline'; document.getElementById('_137_317_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_137_317_Closed_Image"  alt="" /></span><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >void</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;create_door_config(pool&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >p,&nbsp;server_rec&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;s)</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_137_317_Closed_Text" >&#8230;</span><span id="_137_317_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;cf&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;static_cast</span><span style="color: rgb(0, 0, 0);" >&lt;</span><span style="color: rgb(0, 0, 0);" >mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*&gt;</span><span style="color: rgb(0, 0, 0);" >(ap_palloc(p,&nbsp;</span><span style="color: rgb(0, 0, 255);" >sizeof</span><span style="color: rgb(0, 0, 0);" >(mod_door_config)));<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cf</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >MaxNumber&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >100</span><span style="color: rgb(0, 0, 0);" >;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cf</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >TimeLimit&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >60</span><span style="color: rgb(0, 0, 0);" >;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >return</span><span style="color: rgb(0, 0, 0);" >&nbsp;cf;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /></span></div>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 通过ap_palloc为全局配置结构分配资源，并初始化配置结构。然后定义命令表。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  onclick="this.style.display='none'; document.getElementById('_39_247_Open_Text').style.display='none'; document.getElementById('_39_247_Closed_Image').style.display='inline'; document.getElementById('_39_247_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_39_247_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_39_247_Closed_Text').style.display='none'; document.getElementById('_39_247_Open_Image').style.display='inline'; document.getElementById('_39_247_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_39_247_Closed_Image"  alt="" /><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;command_rec&nbsp;door_cmds[]&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_39_247_Closed_Text" >&#8230;</span><span id="_39_247_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_49_134_Open_Text').style.display='none'; document.getElementById('_49_134_Closed_Image').style.display='inline'; document.getElementById('_49_134_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"  id="_49_134_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_49_134_Closed_Text').style.display='none'; document.getElementById('_49_134_Open_Image').style.display='inline'; document.getElementById('_49_134_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"  id="_49_134_Closed_Image"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_49_134_Closed_Text" >&#8230;</span><span id="_49_134_Open_Text" ><span style="color: rgb(0, 0, 0);" >{</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >MaxRequest</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >,&nbsp;maxRequest,&nbsp;NULL,&nbsp;RSRC_CONF</span><span style="color: rgb(0, 0, 0);" >|</span><span style="color: rgb(0, 0, 0);" >ACCESS_CONF,&nbsp;TAKE1,&nbsp;</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >Can&#8217;t&nbsp;get&nbsp;MaxRequest</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >}</span></span><span style="color: rgb(0, 0, 0);" >,<br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_145_229_Open_Text').style.display='none'; document.getElementById('_145_229_Closed_Image').style.display='inline'; document.getElementById('_145_229_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"  id="_145_229_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_145_229_Closed_Text').style.display='none'; document.getElementById('_145_229_Open_Image').style.display='inline'; document.getElementById('_145_229_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"  id="_145_229_Closed_Image"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_145_229_Closed_Text" >&#8230;</span><span id="_145_229_Open_Text" ><span style="color: rgb(0, 0, 0);" >{</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >TimeRange</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >,&nbsp;timeRange,&nbsp;&nbsp;NULL,&nbsp;RSRC_CONF</span><span style="color: rgb(0, 0, 0);" >|</span><span style="color: rgb(0, 0, 0);" >ACCESS_CONF,&nbsp;TAKE1,&nbsp;</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >Cant&#8217;&nbsp;get&nbsp;Time&nbsp;Range</span><span style="color: rgb(0, 0, 0);" >&quot;</span><span style="color: rgb(0, 0, 0);" >}</span></span><span style="color: rgb(0, 0, 0);" >,<br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_240_245_Open_Text').style.display='none'; document.getElementById('_240_245_Closed_Image').style.display='inline'; document.getElementById('_240_245_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif"  id="_240_245_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_240_245_Closed_Text').style.display='none'; document.getElementById('_240_245_Open_Image').style.display='inline'; document.getElementById('_240_245_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif"  id="_240_245_Closed_Image"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_240_245_Closed_Text" >&#8230;</span><span id="_240_245_Open_Text" ><span style="color: rgb(0, 0, 0);" >{NULL}</span></span><span style="color: rgb(0, 0, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" >;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /></span></div>
</div>
<p>&nbsp;&nbsp; 接着定义命令处理函数：</p>
<p>&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  onclick="this.style.display='none'; document.getElementById('_79_328_Open_Text').style.display='none'; document.getElementById('_79_328_Closed_Image').style.display='inline'; document.getElementById('_79_328_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_79_328_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_79_328_Closed_Text').style.display='none'; document.getElementById('_79_328_Open_Image').style.display='inline'; document.getElementById('_79_328_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_79_328_Closed_Image"  alt="" /><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;maxRequest(cmd_parms&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cmd,&nbsp;</span><span style="color: rgb(0, 0, 255);" >void</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;dconf,&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;arg)</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_79_328_Closed_Text" >&#8230;</span><span id="_79_328_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server_rec&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;s&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;cmd</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >server;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cf&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;static_cast</span><span style="color: rgb(0, 0, 0);" >&lt;</span><span style="color: rgb(0, 0, 0);" >mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*&gt;</span><span style="color: rgb(0, 0, 0);" >(ap_get_module_config(s</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >module_config,&nbsp;</span><span style="color: rgb(0, 0, 0);" >&amp;</span><span style="color: rgb(0, 0, 0);" >door_module));<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cf</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >MaxNumber&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;atoi(arg);<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >cerr&lt;&lt;cf-&gt;MaxNumber&lt;&lt;endl;</span><span style="color: rgb(0, 128, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >return</span><span style="color: rgb(0, 0, 0);" >&nbsp;NULL;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" ><br/>
<img align="top"  onclick="this.style.display='none'; document.getElementById('_409_658_Open_Text').style.display='none'; document.getElementById('_409_658_Closed_Image').style.display='inline'; document.getElementById('_409_658_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_409_658_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_409_658_Closed_Text').style.display='none'; document.getElementById('_409_658_Open_Image').style.display='inline'; document.getElementById('_409_658_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_409_658_Closed_Image"  alt="" /></span><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;timeRange(cmd_parms&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cmd,&nbsp;</span><span style="color: rgb(0, 0, 255);" >void</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;dconf,&nbsp;</span><span style="color: rgb(0, 0, 255);" >const</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >char</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;arg)</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_409_658_Closed_Text" >&#8230;</span><span id="_409_658_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server_rec&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;s&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;cmd</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >server;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >cf&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;static_cast</span><span style="color: rgb(0, 0, 0);" >&lt;</span><span style="color: rgb(0, 0, 0);" >mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*&gt;</span><span style="color: rgb(0, 0, 0);" >(ap_get_module_config(s</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >module_config,&nbsp;</span><span style="color: rgb(0, 0, 0);" >&amp;</span><span style="color: rgb(0, 0, 0);" >door_module));<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cf</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >TimeLimit&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;atoi(arg);<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >cerr&lt;&lt;cf-&gt;TimeLimit&lt;&lt;endl;</span><span style="color: rgb(0, 128, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >return</span><span style="color: rgb(0, 0, 0);" >&nbsp;NULL;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /></span></div>
</div>
<p>最后在验证阶段，来获取配置信息：</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;" >
<div><img align="top"  onclick="this.style.display='none'; document.getElementById('_46_469_Open_Text').style.display='none'; document.getElementById('_46_469_Closed_Image').style.display='inline'; document.getElementById('_46_469_Closed_Text').style.display='inline';"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"  id="_46_469_Open_Image"  alt="" /><img align="top"  onclick="this.style.display='none'; document.getElementById('_46_469_Closed_Text').style.display='none'; document.getElementById('_46_469_Open_Image').style.display='inline'; document.getElementById('_46_469_Open_Text').style.display='inline';"  style="display: none;"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"  id="_46_469_Closed_Image"  alt="" /><span style="color: rgb(0, 0, 255);" >static</span><span style="color: rgb(0, 0, 0);" >&nbsp;</span><span style="color: rgb(0, 0, 255);" >int</span><span style="color: rgb(0, 0, 0);" >&nbsp;door_authorization(request_rec&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;r)</span><span style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"  id="_46_469_Closed_Text" >&#8230;</span><span id="_46_469_Open_Text" ><span style="color: rgb(0, 0, 0);" >{<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cerr&nbsp;</span><span style="color: rgb(0, 0, 0);" >&lt;&lt;</span><span style="color: rgb(0, 0, 0);" >&nbsp;r</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >connection</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >remote_ip</span><span style="color: rgb(0, 0, 0);" >&lt;&lt;</span><span style="color: rgb(0, 0, 0);" >endl;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*</span><span style="color: rgb(0, 0, 0);" >&nbsp;cf&nbsp;</span><span style="color: rgb(0, 0, 0);" >=</span><span style="color: rgb(0, 0, 0);" >&nbsp;static_cast</span><span style="color: rgb(0, 0, 0);" >&lt;</span><span style="color: rgb(0, 0, 0);" >mod_door_config&nbsp;</span><span style="color: rgb(0, 0, 0);" >*&gt;</span><span style="color: rgb(0, 0, 0);" >(ap_get_module_config(r</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >server</span><span style="color: rgb(0, 0, 0);" >-&gt;</span><span style="color: rgb(0, 0, 0);" >module_config,&nbsp;</span><span style="color: rgb(0, 0, 0);" >&amp;</span><span style="color: rgb(0, 0, 0);" >door_module));<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >ap_rprintf(r&nbsp;,&quot;your&nbsp;IP&nbsp;:&nbsp;%s&nbsp; &quot;,&nbsp;r-&gt;connection-&gt;remote_ip);<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >ap_rprintf(r&nbsp;,&quot;MaxNumber&nbsp;:&nbsp;%d&nbsp; &quot;,&nbsp;cf-&gt;MaxNumber);<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >ap_rprintf(r&nbsp;,&quot;TimeRange&nbsp;:&nbsp;%s&nbsp; &quot;,&nbsp;cf-&gt;TimeLimit);<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);" >//</span><span style="color: rgb(0, 128, 0);" >cerr&lt;&lt;cf-&gt;MaxNumber&lt;&lt;endl;</span><span style="color: rgb(0, 128, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: rgb(0, 0, 0);" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);" >return</span><span style="color: rgb(0, 0, 0);" >&nbsp;OK;<br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: rgb(0, 0, 0);" ><br/>
<img align="top"  src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"  alt="" /></span></div>
</div>
<p>&nbsp;经过编译，测试，一切works well。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;先写这么多，等我慢慢研究这些遗留问题，留待以后补充。</p>
<p>&nbsp;</p>
<p>&nbsp;ps: 看源代码，是最快的学习方法。</p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/04/09/112.html#comment-185" >2008/09/25</a>, fy writes: 《Aapache源码分析》??</li><li><a href="http://www.laruence.com/2008/04/09/112.html#comment-190" >2008/09/25</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 这个不算源码分析，只是我当时记录的一点心得.:)</li><li><a href="http://www.laruence.com/2008/04/09/112.html#comment-2596" >2010/05/20</a>, whut_avatar writes: 您好 ！

    我一直使用C语言来编写Apache模块的，现在想在我的handler中生成SAML断言，发送给后台的APP，因此想到了用OPENSaml，可是这个库只有C++的 ，因此就想在C中怎么调用C++的库。看到你这篇文章后，想问下你，面对这种情况我该怎么搞 ？Apache模块编写中怎么去调用一个C++的库，再说在用Apache编译工具apxs编译的时候，它根本就不能处理C++函数。</li><li><a href="http://www.laruence.com/2008/04/09/112.html#comment-2597" >2010/05/20</a>, whut_avatar writes: 请指教，小弟先表示谢意！</li><li><a href="http://www.laruence.com/2008/04/09/112.html#comment-2601" >2010/05/20</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @whut_avatar 不好意思, N年前搞的了, 现在对这块已经不熟悉了, 爱莫能助.</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/04/09/112.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>VIM中文乱码解决方案</title>
		<link>http://www.laruence.com/2007/10/03/5.html</link>
		<comments>http://www.laruence.com/2007/10/03/5.html#comments</comments>
		<pubDate>Wed, 03 Oct 2007 05:11:08 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=5</guid>
		<description><![CDATA[

作者: laruence(http://www.laruence.com)
本文地址: http://www.laruence.com/2007/10/03/5.html
转载请注明出处 


set langmenu=zh_CN.utf8
set fileencodings=utf-8,cp936,big5,latin1
set ambiwidth=double
let $LANG=’en’
或者也可以:
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has(&#8220;win32&#8243;)
set fileencoding=chinese
else
set fileencoding=utf-8
endif
&#8220;解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
&#8220;解决consle输出乱码
language messages zh_CN.utf-8
下面的方法经过我测试，是可以完美解决的，第一种没有经过测试

Comments2010/01/01, Ferro&#39;s Home &#187; Text Editor writes: [...] VIM中文乱码 set encoding=utf-8 set fileencodings=utf-8,chinese,latin-1 if has(“win32″) set [...]Copyright &#169; 2010 风雪之隅 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: laruence(<a href="http://www.laruence.com"  title="风雪之隅"  target="_blank" >http://www.laruence.com</a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2007/10/03/5.html"  title="Permanet Link to VIM中文乱码解决方案" >http://www.laruence.com/2007/10/03/5.html</a></li>
<li>转载请注明出处 </li>
</ul></div>
<div id="msgcns!BDC1482E8FA76F7D!210"  class="bvMsg" >
<div>set langmenu=zh_CN.utf8<br/>
set fileencodings=utf-8,cp936,big5,latin1<br/>
set ambiwidth=double<br/>
let $LANG=’en’</div>
<div>或者也可以:</div>
<div><span style="font-family: Courier New;" >set encoding=utf-8<br/>
set fileencodings=utf-8,chinese,latin-1<br/>
if has(&#8220;win32&#8243;)<br/>
set fileencoding=chinese<br/>
else<br/>
set fileencoding=utf-8<br/>
endif<br/>
&#8220;解决菜单乱码<br/>
source $VIMRUNTIME/delmenu.vim<br/>
source $VIMRUNTIME/menu.vim<br/>
&#8220;解决consle输出乱码<br/>
language messages zh_CN.utf-8</span></div>
<div><span style="font-family: Courier New;" >下面的方法经过我测试，是可以完美解决的，第一种没有经过测试</span></div>
</div>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2007/10/03/5.html#comment-2402" >2010/01/01</a>, <a href="http://ferrofang.net/2010/01/01/text-editor/"  rel="external nofollow"  class="url" >Ferro&#39;s Home &raquo; Text Editor</a> writes: [...] VIM中文乱码 set encoding=utf-8 set fileencodings=utf-8,chinese,latin-1 if has(“win32″) set [...]</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2007/10/03/5.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
