<?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引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:59:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Apache Access Log中的Options的含义</title>
		<link>http://www.laruence.com/2011/05/05/2002.html</link>
		<comments>http://www.laruence.com/2011/05/05/2002.html#comments</comments>
		<pubDate>Thu, 05 May 2011 08:24:32 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[127.0.0.1]]></category>
		<category><![CDATA[access log]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[internal dummy connection]]></category>
		<category><![CDATA[OPTIONS]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=2002</guid>
		<description><![CDATA[<p>
   说是, 在Apache的Access Log中会看到很多如下的访问日志:
<coolcode lang="bash" linenum="off">
127.0.0.1 - - [05/May/2011:10:54:07 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:08 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:09 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:10 +0800] "OPTIONS * HTTP/1.0" 200 -
</coolcode>
   这是什么意思呢?
</p>]]></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" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2011/05/05/2002.html"  title="Permanet Link to Apache Access Log中的Options的含义" >http://www.laruence.com/2011/05/05/2002.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    写博客最怕啥,,,最怕没话题, 没说的, 呵呵</p>
<p>    好在公司内的PHP群里,同学众多, 于是又有了今天的这个话题.
</p>
<p>
   说是, 在Apache的Access Log中会看到很多如下的访问日志:</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;">
127.0.0.1 - - [05/May/2011:10:54:07 +0800] &quot;OPTIONS * HTTP/1.0&quot; 200 -
127.0.0.1 - - [05/May/2011:10:54:08 +0800] &quot;OPTIONS * HTTP/1.0&quot; 200 -
127.0.0.1 - - [05/May/2011:10:54:09 +0800] &quot;OPTIONS * HTTP/1.0&quot; 200 -
127.0.0.1 - - [05/May/2011:10:54:10 +0800] &quot;OPTIONS * HTTP/1.0&quot; 200 -
</pre>
<p>   这是什么意思呢?
</p>
<p>
   Apache的文档中, 有如下的说明:</p>
<blockquote><p>
When the Apache HTTP Server manages its child processes, it needs a way to wake up processes that are listening for new connections. To do this, it sends a simple HTTP request back to itself. This request will appear in the access_log file with the remote address set to the loop-back interface (typically 127.0.0.1 or ::1 if IPv6 is configured). If you log the User-Agent string (as in the combined log format), you will see the server signature followed by &#8220;(internal dummy connection)&#8221; on non-SSL servers. During certain periods you may see up to one such request for each httpd child process.
</p></blockquote>
<p>   可是, 为什么要唤醒呢? 唤醒是为了做什么呢? </p>
<p>   在Apache Prefork模式下,  启动的时候, Apache就会fork出一些worker进程, 来准备接受请求, 这些worker进程, 在完成准备工作以后, 就会进入block模式的监听沉睡中, 等待请求到来而被唤醒.</p>
<p>   另外一方面, 在Prefork模式下, 当请求很多, 目前的worker进程数不够处理的时候, 就会额外再fork一些worker进程出来, 以满足当前的请求.(参看:http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html).</p>
<p>   而在这些请求高峰过后, 如果额外fork出来的进程数大于了MaxSpareServers, Apache就会告诉这些worker进程退出, 那么问题就来了,,</p>
<p>   这些进程都在沉睡中啊, 怎么告诉他们, 并且让他们自我退出呢?</p>
<p>   Apache会首先发送一个退出状态字(GRACEFUL_CHAR !)给这些Work进程.</p>
<pre name="code"  class="sh_c"  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;">
static apr_status_t pod_signal_internal(ap_pod_t *pod)
{
    apr_status_t rv;
    char char_of_death = '!';
    apr_size_t one = 1;

    rv = apr_file_write(pod-&gt;pod_out, &amp;char_of_death, &amp;one);
    if (rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
                     &quot;write pipe_of_death&quot;);
    }

    return rv;
}
</pre>
<p>   但此时, Worker进程不会去读这些状态字, 因为他们还在沉睡.</p>
<p>   这个时候Apache就会发送一个OPTIONS请求给自己, 唤醒这些沉睡的进程.</p>
<pre name="code"  class="sh_c"  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;">
static apr_status_t dummy_connection(ap_pod_t *pod)
{
//...有省略
    /* Create the request string. We include a User-Agent so that
     * adminstrators can track down the cause of the odd-looking
     * requests in their logs.
     */
    srequest = apr_pstrcat(p, &quot;OPTIONS * HTTP/1.0\r\nUser-Agent: &quot;,
                           ap_get_server_banner(),
                           &quot; (internal dummy connection)\r\n\r\n&quot;, NULL);
//...有省略
}
</pre>
<p>   这些进程在处理完当前请求以后(OPTIONS请求), 就会发现, oh, 主进程让我退出,</p>
<pre name="code"  class="sh_c"  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;">
static void child_main(int child_num_arg)
{
//...有省略

    while (!die_now &amp;&amp; !shutdown_pending) {
//...有省略
        //1. listen
        //2. accept
        //3. process request

        /* Check the pod and the generation number after processing a
         * connection so that we'll go away if a graceful restart occurred
         * while we were processing the connection or we are the lucky
         * idle server process that gets to die.
         */
        if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
            die_now = 1;
        }
//...有省略
   }
//...有省略
}
</pre>
<p>   于是, 它就做完清理工作,, 然后自我消亡了~~~</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_c.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_c.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_c.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/2011/05/05/2002.html" >2011/06/02</a>, <a href="http://blog.thinkinlamp.com/?p=746"  rel="external nofollow"  class="url" >Thinking In LAMP Blog &raquo; Blog Archive &raquo; PHP每月通讯（2011年6月）</a> writes: [...] http://www.laruence.com/2011/05/05/2002.html 　　Apache Access Log中的Options的含义 [...]</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/10/26/1768.html"  rel="bookmark"  title="Permanent Link: AllowEncodedSlashes in Apache" >AllowEncodedSlashes in Apache</a></li><li><a href="http://www.laruence.com/2008/08/22/389.html"  rel="bookmark"  title="Permanent Link: Apache主导全美100大网站" >Apache主导全美100大网站</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  rel="bookmark"  title="Permanent Link: 通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2011/11/11/2296.html"  rel="bookmark"  title="Permanent Link: PHP5.4新特性-解引用实例化" >PHP5.4新特性-解引用实例化</a></li><li><a href="http://www.laruence.com/2011/02/13/1870.html"  rel="bookmark"  title="Permanent Link: 加速PHP的ECHO" >加速PHP的ECHO</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2010/10/26/1768.html"  title="AllowEncodedSlashes in Apache" >AllowEncodedSlashes in Apache</a></li><li><a href="http://www.laruence.com/2008/07/24/206.html"  title="Apache启动过程(PHP_MINIT_FUNCTION的调用)" >Apache启动过程(PHP_MINIT_FUNCTION的调用)</a></li><li><a href="http://www.laruence.com/2008/04/17/110.html"  title="页面乱码问题根源浅析" >页面乱码问题根源浅析</a></li><li><a href="http://www.laruence.com/2008/04/09/112.html"  title="使用C++编写Apache的模块 &#8212; 命令表,保存配置信息" >使用C++编写Apache的模块 &#8212; 命令表,保存配置信息</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2011/05/05/2002.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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://laruence-wordpress.stor.sinaapp.com/uploads/metion.jpg" ><img src="http://laruence-wordpress.stor.sinaapp.com/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://laruence-wordpress.stor.sinaapp.com/uploads/list.jpg" ><img src="http://laruence-wordpress.stor.sinaapp.com/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" >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" >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" >2010/05/25</a>, 小熊 writes: 劳伦斯叔叔太强大了</li><li><a href="http://www.laruence.com/2010/05/24/1526.html" >2010/05/25</a>, <a href="http://topsy.com/trackback?utm_source=pingback&#038;utm_campaign=L2&#038;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" >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" >2010/05/27</a>, evan writes: encodeURL 方法似乎有问题，不能发推，接收没问题。注释掉之后就能正常发推了</li><li><a href="http://www.laruence.com/2010/05/24/1526.html" >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" >2010/06/10</a>, <a href="http://www.xingai114.com"  rel="external nofollow"  class="url" >xingai</a> writes: 这个比较帅............</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/09/30/2179.html"  rel="bookmark"  title="Permanent Link: PHP正则之递归匹配" >PHP正则之递归匹配</a></li><li><a href="http://www.laruence.com/2011/11/18/2305.html"  rel="bookmark"  title="Permanent Link: GBK编码PHP脚本导致语法错误(Zend Multibyte)" >GBK编码PHP脚本导致语法错误(Zend Multibyte)</a></li><li><a href="http://www.laruence.com/2010/05/24/1515.html"  rel="bookmark"  title="Permanent Link: shell下发推脚本" >shell下发推脚本</a></li><li><a href="http://www.laruence.com/2011/12/06/2381.html"  rel="bookmark"  title="Permanent Link: 更简单的重现PHP Core的调用栈" >更简单的重现PHP Core的调用栈</a></li><li><a href="http://www.laruence.com/2008/06/18/221.html"  rel="bookmark"  title="Permanent Link: 深入理解PHP原理之Opcodes" >深入理解PHP原理之Opcodes</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   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"  title="shell下发推脚本" >shell下发推脚本</a></li></ul>]]></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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >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" >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" >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" >2010/05/24</a>, Brilliance writes: 我的UTF8发出去的汉字是***= =!</li><li><a href="http://www.laruence.com/2010/05/24/1515.html" >2010/05/25</a>, <a href="http://topsy.com/trackback?utm_source=pingback&#038;utm_campaign=L2&#038;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" >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" >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" >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" >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" >2010/07/31</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @mahone 不会, 还需要借助代理, 或者VPN.</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/11/16/1147.html"  rel="bookmark"  title="Permanent Link: 分割GBK中文遭遇乱码的解决" >分割GBK中文遭遇乱码的解决</a></li><li><a href="http://www.laruence.com/2009/07/28/1030.html"  rel="bookmark"  title="Permanent Link: Linux上配置Nginx+PHP5(FastCGI)" >Linux上配置Nginx+PHP5(FastCGI)</a></li><li><a href="http://www.laruence.com/2009/04/24/695.html"  rel="bookmark"  title="Permanent Link: 数组非数字键名引号的必要性" >数组非数字键名引号的必要性</a></li><li><a href="http://www.laruence.com/2008/08/22/412.html"  rel="bookmark"  title="Permanent Link: 深入理解PHP原理之变量(Variables inside PHP)" >深入理解PHP原理之变量(Variables inside PHP)</a></li><li><a href="http://www.laruence.com/2009/06/11/930.html"  rel="bookmark"  title="Permanent Link: PHP CLI模式下的多进程应用" >PHP CLI模式下的多进程应用</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   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"  title="BTwitter(Twitter In Bash)" >BTwitter(Twitter In Bash)</a></li></ul>]]></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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >2010/04/21</a>, evan writes: putty 可以用 scp</li><li><a href="http://www.laruence.com/2010/04/21/1442.html" >2010/04/21</a>, Platinum writes: 一直在 SecureCRT 下用 scp 的路过</li><li><a href="http://www.laruence.com/2010/04/21/1442.html" >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" >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" >2010/04/24</a>, zwws writes: XShell支持, 一直在用, 而且对个人用户的免费的.</li><li><a href="http://www.laruence.com/2010/04/21/1442.html" >2010/04/28</a>, alewater writes: 百度应该是用的relay机器做的中转，还有可恶的token密码，防止密码被盗。</li><li><a href="http://www.laruence.com/2010/04/21/1442.html" >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><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/06/28/2088.html"  title="在Windows下编译Yaf" >在Windows下编译Yaf</a></li><li><a href="http://www.laruence.com/2011/09/22/2152.html"  title="回答下在bugs.php上的一个问题" >回答下在bugs.php上的一个问题</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2008/05/01/106.html"  title="汉字和Unicode码(utf-8)之间的转换(Pack/Unpack)" >汉字和Unicode码(utf-8)之间的转换(Pack/Unpack)</a></li><li><a href="http://www.laruence.com/2008/08/22/389.html"  title="Apache主导全美100大网站" >Apache主导全美100大网站</a></li><li><a href="http://www.laruence.com/2008/04/16/19.html"  title="编写提供对象给PHP使用的Module" >编写提供对象给PHP使用的Module</a></li><li><a href="http://www.laruence.com/2010/02/03/1283.html"  title="Facebook性能大提升的秘密：HipHop" >Facebook性能大提升的秘密：HipHop</a></li><li><a href="http://www.laruence.com/2011/07/16/2123.html"  title="浏览器多tab打开同一URL串行化的问题" >浏览器多tab打开同一URL串行化的问题</a></li><li><a href="http://www.laruence.com/2008/07/21/120.html"  title="PHP Pallas CMS源码公布" >PHP Pallas CMS源码公布</a></li><li><a href="http://www.laruence.com/2009/04/24/695.html"  title="数组非数字键名引号的必要性" >数组非数字键名引号的必要性</a></li></ul>]]></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" >2010/04/18</a>, 小熊 writes: 小熊来拜雪候鸟锅锅</li><li><a href="http://www.laruence.com/2010/04/17/1433.html" >2010/04/18</a>, <a href="http://topsy.com/trackback?utm_source=pingback&#038;utm_campaign=L2&#038;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" >2010/04/18</a>, Yufeng writes: 哈哈，的确是会上瘾的，也说不上来为啥，只感觉别的工具写代码都好像不那么好用……</li><li><a href="http://www.laruence.com/2010/04/17/1433.html" >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" >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" >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" >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" >2010/05/06</a>, yufeng writes: @雪候鸟 唉，当时要是不用就好了，导致心理失衡，看人家用IDE就想推销VIM，还要用力克制推销欲望，只淡淡一句：哦，其实VIM也挺好用的。</li><li><a href="http://www.laruence.com/2010/04/17/1433.html" >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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/08/18/1718.html"  title="将PHP Manual融入(g)Vim" >将PHP Manual融入(g)Vim</a></li><li><a href="http://www.laruence.com/2007/10/03/5.html"  title="VIM中文乱码解决方案" >VIM中文乱码解决方案</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/04/17/1433.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>pkg-config与LD_LIBRARY_PATH</title>
		<link>http://www.laruence.com/2010/01/27/1265.html</link>
		<comments>http://www.laruence.com/2010/01/27/1265.html#comments</comments>
		<pubDate>Wed, 27 Jan 2010 11:34:28 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[GNU C/C++]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[随笔]]></category>
		<category><![CDATA[ld.so.conf]]></category>
		<category><![CDATA[LD_LIBRARY_PATH]]></category>
		<category><![CDATA[pkg-config]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1265</guid>
		<description><![CDATA[    一般来说，如果库的头文件不在 /usr/include 目录中，那么在编译的时候需要用 -I 参数指定其路径。由于同一个库在不同系统上可能位于不同的目录下，用户安装库的时候也可以将库安装在不同的目录下，所以即使使用同一个库，由于库的路径的不同，造成了用 -I 参数指定的头文件的路径也可能不同，其结果就是造成了编译命令界面的不统一。如果使用 -L 参数，也会造成连接界面的不统一。编译和连接界面不统一会为库的使用带来麻烦。

       为了解决编译和连接界面不统一的问题，人们找到了一些解决办法。其基本思想就是：事先把库的位置信息等保存起来，需要的时候再通过特定的工具将其中有用的 信息提取出来供编译和连接使用。这样，就可以做到编译和连接界面的一致性。其中，目前最为常用的库信息提取工具就是下面介绍的 pkg-config...]]></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/01/27/1265.html"  title="Permanet Link to pkg-config与LD_LIBRARY_PATH" >http://www.laruence.com/2010/01/27/1265.html</a></li>
<li>文章转自: <a href="http://hi.baidu.com/litaosmile/blog/item/751be4f45bbb4ee67609d7be.html"  target="_blank" >Lucky_xi的百度空间</a></li>
</ul></div>
<p>最近遇到的几个问题， 都和LD_LIBRARY_PATH有关， 想整理一篇心得， 但发现一片比较好的介绍文章， 就不再赘笔了。</p>
<h3>一、编译和连接</h3>
<p>        一般来说，如果库的头文件不在 /usr/include 目录中，那么在编译的时候需要用 -I 参数指定其路径。由于同一个库在不同系统上可能位于不同的目录下，用户安装库的时候也可以将库安装在不同的目录下，所以即使使用同一个库，由于库的路径的不同，造成了用 -I 参数指定的头文件的路径也可能不同，其结果就是造成了编译命令界面的不统一。如果使用 -L 参数，也会造成连接界面的不统一。编译和连接界面不统一会为库的使用带来麻烦。</p>
<p>       为了解决编译和连接界面不统一的问题，人们找到了一些解决办法。其基本思想就是：事先把库的位置信息等保存起来，需要的时候再通过特定的工具将其中有用的 信息提取出来供编译和连接使用。这样，就可以做到编译和连接界面的一致性。其中，目前最为常用的库信息提取工具就是下面介绍的 pkg-config。</p>
<p>       pkg-config 是通过库提供的一个 .pc 文件获得库的各种必要信息的，包括版本信息、编译和连接需要的参数等。这些信息可以通过 pkg-config 提供的参数单独提取出来直接供编译器和连接器使用。</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;">
  The pkgconfig package contains tools for passing the include path and/or library
paths to build tools during the make file execution.

  pkg-config is a function that returns meta information for the specified library.

  The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix
we use to install pkgconfig. You may add to PKG_CONFIG_PATH by exporting additional
paths on your system where pkgconfig files are installed. Note that PKG_CONFIG_PATH is
only needed when compiling packages, not during run-time.
</pre>
<p>        在默认情况下，每个支持 pkg-config 的库对应的 .pc 文件在安装后都位于安装目录中的 lib/pkgconfig 目录下。例如，我们在上面已经将 Glib 安装在 /opt/gtk 目录下了，那么这个 Glib 库对应的 .pc 文件是 /opt/gtk/lib/pkgconfig 目录下一个叫 glib-2.0.pc 的文件：</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;">
prefix=/opt/gtk/
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: GLib
Description: C Utility Library
Version: 2.12.13
Libs: -L${libdir} -lglib-2.0
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include
</pre>
<p>使用 pkg-config 的 &#8211;cflags 参数可以给出在编译时所需要的选项，而 &#8211;libs 参数可以给出连接时的选项。例如，假设一个 sample.c 的程序用到了 Glib 库，就可以这样编译：</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;">
$ gcc -c `pkg-config --cflags glib-2.0` sample.c
</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;">
$ gcc sample.o -o sample `pkg-config --libs glib-2.0`
</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;">
$ gcc sample.c -o sample `pkg-config --cflags --libs glib-2.0`
</pre>
<p>可以看到：由于使用了 pkg-config 工具来获得库的选项，所以不论库安装在什么目录下，都可以使用相同的编译和连接命令，带来了编译和连接界面的统一。</p>
<p>使用 pkg-config 工具提取库的编译和连接参数有两个基本的前提：</p>
<p>库本身在安装的时候必须提供一个相应的 .pc 文件。不这样做的库说明不支持 pkg-config 工具的使用。</p>
<p>pkg-config 必须知道要到哪里去寻找此 .pc 文件。</p>
<p>GTK+ 及其依赖库支持使用 pkg-config 工具，所以剩下的问题就是如何告诉 pkg-config 到哪里去寻找库对应的 .pc 文件，这也是通过设置搜索路径来解决的。</p>
<p>       对于支持 pkg-config 工具的 GTK+ 及其依赖库来说，库的头文件的搜索路径的设置变成了对 .pc 文件搜索路径的设置。.pc 文件的搜索路径是通过环境变量 PKG_CONFIG_PATH 来设置的，pkg-config 将按照设置路径的先后顺序进行搜索，直到找到指定的 .pc 文件为止。</p>
<p>安装完 Glib 后，在 bash 中应该进行如下设置：</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;">
$ export PKG_CONFIG_PATH=/opt/gtk/lib/pkgconfig:$PKG_CONFIG_PATH
</pre>
<p>可以执行下面的命令检查是否 /opt/gtk/lib/pkgconfig 路径已经设置在 PKG_CONFIG_PATH 环境变量中：</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;">
$ echo $PKG_CONFIG_PATH
</pre>
<p>这样设置之后，使用 Glib 库的其它程序或库在编译的时候 pkg-config 就知道首先要到 /opt/gtk/lib/pkgconfig 这个目录中去寻找 glib-2.0.pc 了（GTK+ 和其它的依赖库的 .pc 文件也将拷贝到这里，也会首先到这里搜索它们对应的 .pc 文件）。之后，通过 pkg-config 就可以把其中库的编译和连接参数提取出来供程序在编译和连接时使用。</p>
<p>另外还需要注意的是：环境变量的设置只对当前的终端窗口有效。如果到了没有进行上述设置的终端窗口中，pkg-config 将找不到新安装的 glib-2.0.pc 文件、从而可能使后面进行的安装（如 Glib 之后的 Atk 的安装）无法进行。</p>
<p>       在我们采用的安装方案中，由于是使用环境变量对 GTK+ 及其依赖库进行的设置，所以当系统重新启动、或者新开一个终端窗口之后，如果想使用新安装的 GTK+ 库，需要如上面那样重新设置 PKG_CONFIG_PATH 和 LD_LIBRARY_PATH 环境变量。</p>
<p>这种使用 GTK+ 的方法，在使用之前多了一个对库进行设置的过程。虽然显得稍微繁琐了一些，但却是一种最安全的使用 GTK+ 库的方式，不会对系统上已经存在的使用了 GTK+ 库的程序（比如 GNOME 桌面）带来任何冲击。</p>
<p>为了使库的设置变得简单一些，可以把下面的这两句设置保存到一个文件中（比如 set_gtk-2.10 文件）:</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;">
export PKG_CONFIG_PATH=/opt/gtk/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/opt/gtk/lib:$LD_LIBRARY_PATH
</pre>
<p>之后，就可以用下面的方法进行库的设置了（其中的 source 命令也可以用 . 代替）：</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;">
$ source set_gtk-2.10
</pre>
<p>只有在用新版的 GTK+ 库开发应用程序、或者运行使用了新版 GTK+ 库的程序的时候，才有必要进行上述设置。</p>
<p>           如果想避免使用 GTK+ 库之前上述设置的麻烦，可以把上面两个环境变量的设置在系统的配置文件中（如 /etc/profile）或者自己的用户配置文件中（如 ~/.bash_profile） ；库的搜索路径也可以设置在 /etc/ld.so.conf 文件中，等等。这种设置在系统启动时会生效，从而会导致使用 GTK+ 的程序使用新版的 GTK+ 运行库，这有可能会带来一些问题。当然，如果你发现用新版的 GTK+ 代替旧版没有什么问题的话，使用这种设置方式是比较方便的。加入到~/.bashrc中，例如：</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;">
PKG_CONFIG_PATH=/opt/gtk/lib/pkgconfig
</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;">
[root@localhost ~]# echo $PKG_CONFIG_PATH
/opt/gtk/lib/pkgconfig
</pre>
<h3> 二、运行时 </h3>
<p>        库文件在连接（静态库和共享库）和运行（仅限于使用共享库的程序）时被使用，其搜索路径是在系统中进行设置的。一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径，所以使用这两个目录中的库时不需要进行设置搜索路径即可直接使用。对于处于默认库搜索路径之外的库，需要将库的位置添加到 库的搜索路径之中。设置库文件的搜索路径有下列两种方式，可任选其一使用：</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;">
在环境变量 LD_LIBRARY_PATH 中指明库的搜索路径。
在 /etc/ld.so.conf 文件中添加库的搜索路径。
</pre>
<p>        将自己可能存放库文件的路径都加入到/etc/ld.so.conf中是明智的选择 ^_^<br/>
添加方法也极其简单，将库文件的绝对路径直接写进去就OK了，一行一个。例如：</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;">
/usr/X11R6/lib
/usr/local/lib
/opt/lib
</pre>
<p>        需要注意的是：第二种搜索路径的设置方式对于程序连接时的库（包括共享库和静态库）的定位已经足够了，但是对于使用了共享库的程序的执行还是不够的。这是 因为为了加快程序执行时对共享库的定位速度，避免使用搜索路径查找共享库的低效率，所以是直接读取库列表文件 /etc/ld.so.cache 从中进行搜索的。/etc/ld.so.cache 是一个非文本的数据文件，不能直接编辑，它是根据 /etc/ld.so.conf 中设置的搜索路径由 /sbin/ldconfig 命令将这些搜索路径下的共享库文件集中在一起而生成的（ldconfig 命令要以 root 权限执行）。因此，为了保证程序执行时对库的定位，在 /etc/ld.so.conf 中进行了库搜索路径的设置之后，还必须要运行 /sbin/ldconfig 命令更新 /etc/ld.so.cache 文件之后才可以。ldconfig ,简单的说，它的作用就是将/etc/ld.so.conf列出的路径下的库文件 缓存到/etc/ld.so.cache 以供使用。因此当安装完一些库文件，(例如刚安装好glib)，或者修改ld.so.conf增加新的库路径后，需要运行一下 /sbin/ldco                                 .cache中，如果没做，即使库文件明明就在/usr/lib下的，也是不会被使用 的，结果编译                                现明明就在那放着，搞的想大骂computer蠢猪一个。 ^_^</p>
<p>       在程序连接时，对于库文件（静态库和共享库）的搜索路径，除了上面的设置方式                                 。因为用 -L 设置的路径将被优先搜索，所以在连接的时候通常都会以这种方式直接指定</p>
<p>        前面已经说明过了，库搜索路径的设置有两种方式：在环境变量 LD_LIBRARY_PA                                文件中设置。其中，第二种设置方式需要 root 权限，以改变 /etc/ld.so.conf 文件并执                                 系统重新启动后，所有的基于 GTK2 的程序在运行时都将使用新安装的 GTK+ 库。不幸的                                会给应用程序带来兼容性的问题，造成某些程序运行不正常。为了避免出现上面的这些情                                中对于库的搜索路径的设置将采用第一种方式进行。这种设置方式不需要 root 权限，设</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;">
$ export LD_LIBRARY_PATH=/opt/gtk/lib:$LD_LIBRARY_PATH
</pre>
<p>可以用下面的命令查看 LD_LIBRAY_PATH 的设置内容：</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;">
$ echo $LD_LIBRARY_PATH
</pre>
<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><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_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_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_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_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_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_bash.js" ></script></p>
<hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/11/11/606.html"  rel="bookmark"  title="Permanent Link: 图解aclocal、autoconf、automake、autoheader、configure" >图解aclocal、autoconf、automake、autoheader、configure</a></li><li><a href="http://www.laruence.com/2008/08/19/327.html"  rel="bookmark"  title="Permanent Link: 用Tidy优化你的HTML(Optimizing HTML with Tidy)" >用Tidy优化你的HTML(Optimizing HTML with Tidy)</a></li><li><a href="http://www.laruence.com/2011/10/05/2192.html"  rel="bookmark"  title="Permanent Link: mysqlnd插件mysqlnd_ms的介绍" >mysqlnd插件mysqlnd_ms的介绍</a></li><li><a href="http://www.laruence.com/2008/08/21/358.html"  rel="bookmark"  title="Permanent Link: Firefox DNS Cache 清除 扩展 V0.1" >Firefox DNS Cache 清除 扩展 V0.1</a></li><li><a href="http://www.laruence.com/2008/08/16/301.html"  rel="bookmark"  title="Permanent Link: 扩展PHP[Extending PHP](一)" >扩展PHP[Extending PHP](一)</a></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><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/05/21/829.html"  title="JS文件装载器(Eve Js Loader)" >JS文件装载器(Eve Js Loader)</a></li><li><a href="http://www.laruence.com/2008/08/22/404.html"  title="寻找函数定义在哪个模块" >寻找函数定义在哪个模块</a></li><li><a href="http://www.laruence.com/2011/07/16/2123.html"  title="浏览器多tab打开同一URL串行化的问题" >浏览器多tab打开同一URL串行化的问题</a></li><li><a href="http://www.laruence.com/2007/10/03/5.html"  title="VIM中文乱码解决方案" >VIM中文乱码解决方案</a></li><li><a href="http://www.laruence.com/2007/12/16/308.html"  title="PHP:Header" >PHP:Header</a></li><li><a href="http://www.laruence.com/2009/07/23/994.html"  title="PHP中的Hash算法" >PHP中的Hash算法</a></li><li><a href="http://www.laruence.com/2011/11/05/2262.html"  title="Yaf的性能对比测试" >Yaf的性能对比测试</a></li><li><a href="http://www.laruence.com/2008/08/17/313.html"  title="PHP的老式语法" >PHP的老式语法</a></li><li><a href="http://www.laruence.com/2009/04/09/674.html"  title="关于Javascript的作用域链的几句话" >关于Javascript的作用域链的几句话</a></li><li><a href="http://www.laruence.com/2008/08/27/472.html"  title="通过访客分布看中国IT业的发展" >通过访客分布看中国IT业的发展</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2010/01/27/1265.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>automake,autoconf使用详解</title>
		<link>http://www.laruence.com/2009/11/18/1154.html</link>
		<comments>http://www.laruence.com/2009/11/18/1154.html#comments</comments>
		<pubDate>Wed, 18 Nov 2009 08:37:50 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[GNU C/C++]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[转载]]></category>
		<category><![CDATA[aclocal]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[automake]]></category>
		<category><![CDATA[configure]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1154</guid>
		<description><![CDATA[    作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的Makefile就不那么容易了.

    在本文中,将给大家介绍如何使用autoconf和automake两个工具来帮助我们自动地生成符合自由软件惯例的 Makefile,这样就可以象常见的 GNU程序一样,只要使用"./configure","make","make instal"就可以把程序安装到Linux系统中去了.

    这将特别适合想做开放源代码软件的程序开发人员,又或如果你只是自己写些小的Toy程序,那么这个文章对你也会有很大的帮助.
转自:<a href="http://www.linuxcomputer.cn/jishuwendang/xinshourumen/200902/03-3029.html">http://www.linuxcomputer.cn/jishuwendang/xinshourumen/200902/03-3029.html</a>]]></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/11/18/1154.html"  title="Permanet Link to automake,autoconf使用详解" >http://www.laruence.com/2009/11/18/1154.html</a></li>
<li>文章转自: <a href="http://www.linuxcomputer.cn/jishuwendang/xinshourumen/200902/03-3029.html" >http://www.linuxcomputer.cn/</a></li>
</ul></div>
<p>	作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的Makefile就不那么容易了.</p>
<p>	在本文中,将给大家介绍如何使用autoconf和automake两个工具来帮助我们自动地生成符合自由软件惯例的 Makefile,这样就可以象常见的 GNU程序一样,只要使用&#8221;./configure&#8221;,&#8221;make&#8221;,&#8221;make instal&#8221;就可以把程序安装到Linux系统中去了.</p>
<p>       这将特别适合想做开放源代码软件的程序开发人员,又或如果你只是自己写些小的Toy程序,那么这个文章对你也会有很大的帮助.<br/>
　<br/>
<h3>一.Makefile介绍</h3>
<p>　　Makefile是用于自动编译和链接的 ,一个工程有很多文件组成,每一个文件的改变都会导致工程的重新链接,但是不是 所有的文件都需要重新编译,Makefile中纪录有文件的信息,在 make时会决定在链接的时候需要重新编译哪些文件.<br/>
　<br/>
　	Makefile的宗旨就是 ：让编译器知道要编译一个文件需要依赖其他的 哪些文件.当那些依赖文件有了改变,编译器会自动的发现最终的生成文件已经过时,而重新编译相应的 模块.<br/>
　　<br/>
	Makefile的 基本结构不是 很复杂,但当一个程序开发人员开始写Makefile时,经常会怀疑自己写的 是 否符合惯例,而且自己写的 Makefile经常和自己的 开发环境相关联,当系统环境变量或路径发生了变化后,Makefile可能还要跟着修改.这样就造成了手工书写Makefile的 诸多问题,automake恰好能很好地帮助我们解决这些问题.<br/>
　　<br/>
	使用automake,程序开发人员只需要写一些简单的 含有预定义宏的 文件,由autoconf根据一个宏文件生成configure,由automake根据另一个宏文件生成Makefile.in,再使用configure依据Makefile.in来生成一个符合惯例的 Makefile.下面我们将详细介绍Makefile的 automake生成方法.<br/>
　　</p>
<h3>二.使用的 环境</h3>
<p>　　本文所提到的 程序是 基于Linux发行版本：Fedora Core release 1,它包含了我们要用到的 autoconf,automake.</p>
<p>　　<br/>
<h3>三.从helloworld入手</h3>
<p>　　我们从大家最常使用的 例子程序helloworld开始.</p>
<p>　　下面的 过程如果简单地说来就是 ：</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;">
　　　helloworld.c
　　　configure.in
　　　Makefile.am
</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;">
aclocal; autoconf; automake --add-missing; ./configure; make; ./helloworld
</pre>
<p>　　就可以看到Makefile被产生出来,而且可以将helloworld.c编译通过.</p>
<p>　　很简单吧,几条命令就可以做出一个符合惯例的 Makefile,感觉如何呀.</p>
<p>　　<b>现在 开始介绍详细的 过程：</b></p>
<p>　　1.建目录</p>
<p>　　在 你的 工作目录下建一个helloworld目录,我们用它来存放helloworld程序及相关文件,如在 /home/my/build下：</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;">
$ mkdir helloword
$ cd helloworld
</pre>
<p>　　2. helloworld.c</p>
<p>　　然后用你自己最喜欢的 编辑器写一个hellowrold.c文件,如命令：vi helloworld.c.使用下面的 代码作为helloworld.c的 内容.</p>
<pre name="code"  class="sh_c"  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;">
#include &lt;stdio.h&gt;
int main(int argc, char** argv){
	printf(&quot;%s&quot;, 'Hello, Linux World!\n&quot;);
	return 0;
}
</pre>
<p>　　完成后保存退出.<br/>
　　现在 在 helloworld目录下就应该有一个你自己写的 helloworld.c了.</p>
<p>　　3.生成configure</p>
<p>　　我们使用autoscan命令来帮助我们根据目录下的 源代码生成一个configure.in的 模板文件.<br/>
　　命令：</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;">
$ autoscan
$ ls
configure.scan helloworld.c
</pre>
<p>　　执行后在 hellowrold目录下会生成一个文件：configure.scan,我们可以拿它作为configure.in的 蓝本.<br/>
　　现在 将configure.scan改名为configure.in,并且编辑它,按下面的 内容修改,去掉无关的 语句：</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;">
==========================configure.in内容开始=========================================
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT(helloworld.c)
AM_INIT_AUTOMAKE(helloworld, 1.0)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
==========================configure.in内容结束=========================================
</pre>
<p>　　然后执行命令aclocal和autoconf,分别会产生aclocal.m4及configure两个文件：</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;">
$ aclocal
$ls
aclocal.m4 configure.in helloworld.c
$ autoconf
$ ls
aclocal.m4 autom4te.cache configure configure.in helloworld.c
</pre>
<p>　　大家可以看到configure.in内容是 一些宏定义,这些宏经autoconf处理后会变成检查系统特性.环境变量.软件必须的 参数的 shell脚本.</p>
<p>　　autoconf 是 用来生成自动配置软件源代码脚本（configure）的 工具.configure脚本能独立于autoconf运行,且在 运行的 过程中,不需要用户的 干预.</p>
<p>　　要生成configure文件,你必须告诉autoconf如何找到你所用的 宏.方式是 使用aclocal程序来生成你的 aclocal.m4.</p>
<p>　　aclocal根据configure.in文件的 内容,自动生成aclocal.m4文件.aclocal是 一个perl 脚本程序,它的 定义是 ：&#8221;aclocal &#8211; create aclocal.m4 by scanning configure.ac&#8221;.</p>
<p>　　autoconf从configure.in这个列举编译软件时所需要各种参数的 模板文件中创建configure.</p>
<p>　　autoconf需要GNU m4宏处理器来处理aclocal.m4,生成configure脚本.</p>
<p>　　m4是 一个宏处理器.将输入拷贝到输出,同时将宏展开.宏可以是 内嵌的 ,也可以是 用户定义的 .除了可以展开宏,m4还有一些内建的 函数,用来引用文件,执行命令,整数运算,文本操作,循环等.m4既可以作为编译器的 前端,也可以单独作为一个宏处理器.</p>
<p>4.新建Makefile.am<br/>
　　新建Makefile.am文件,命令：</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;">
$ vi Makefile.am
　　内容如下:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c
</pre>
<p>　　automake会根据你写的 Makefile.am来自动生成Makefile.in.</p>
<p>　　Makefile.am中定义的 宏和目标,会指导automake生成指定的 代码.例如,宏bin_PROGRAMS将导致编译和连接的 目标被生成.<br/>
　　5.运行automake:</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;">
$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
</pre>
<p>　　automake会根据Makefile.am文件产生一些文件,包含最重要的 Makefile.in.</p>
<p>　　6.执行configure生成Makefile</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;">
$./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
$ ls -l Makefile
-rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile
</pre>
<p>你可以看到,此时Makefile已经产生出来了.</p>
<p>7.使用Makefile编译代码</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;">
$make
if gcc -DPACKAGE_NAME=\&quot;FULL-PACKAGE-NAME\&quot; -DPACKAGE_TARNAME=\&quot;full-package-name\&quot; -DPACKAGE_VERSION=\&quot;VERSION\&quot; -DPACKAGE_STRING=\&quot;FULL-PACKAGE-NAME\ VERSION\&quot; -DPACKAGE_BUGREPORT=\&quot;BUG-REPORT-ADDRESS\&quot; -DPACKAGE=\&quot;helloworld\&quot; -DVERSION=\&quot;1.0\&quot; -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1  -I. -I.     -g -O2 -MT helloworld.o -MD -MP -MF &quot;.deps/helloworld.Tpo&quot; -c -o helloworld.o helloworld.c; \
then mv -f &quot;.deps/helloworld.Tpo&quot; &quot;.deps/helloworld.Po&quot;; else rm -f &quot;.deps/helloworld.Tpo&quot;; exit 1; fi
gcc  -g -O2   -o helloworld  helloworld.o
</pre>
<p>　　运行helloworld</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;">
$ ./helloworld
Hello, Linux World!
</pre>
<p>　　这样helloworld就编译出来了,你如果按上面的 步骤来做的 话,应该也会很容易地编译出正确的 helloworld文件.你还可以试着使用一些其他的 make命令,如make clean,make install,make dist,看看它们会给你什么样的 效果.感觉如何？自己也能写出这么专业的 Makefile,老板一定会对你刮目相看.</p>
<h3>四.深入浅出</h3>
<p>　　针对上面提到的 各个命令,我们再做些详细的 介绍.</p>
<pre  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. autoscan
　　autoscan是 用来扫描源代码目录生成configure.scan文件的 .autoscan
可以用目录名做为参数,但如果你不使用参数的 话,那么autoscan将认为使用的是当前目录.
autoscan将扫描你所指定目录中的 源文件,并创建configure.scan文件.
　　2. configure.scan
　　configure.scan包含了系统配置的 基本选项,里面都是 一些宏定义.我们需要将它改名为
configure.in
　　3. aclocal
　　aclocal是 一个perl 脚本程序.aclocal根据configure.in文件的 内容
,自动生成aclocal.m4文件.aclocal的 定义是 ："aclocal - create
aclocal.m4 by scanning configure.ac".
　　4. autoconf
　　autoconf是 用来产生configure文件的 .configure是 一个脚本,它能设置
源程序来适应各种不同的操作系统平台,并且根据不同的 系统来产生合适的 Makefile,从而可以使
你的源代码能在不同的操作系统平台上被编译出来.
　　configure.in文件的 内容是 一些宏,这些宏经过autoconf 处理后会变成检查系统
特性.环境变量.软件必须的 参数的 shell脚本.configure.in文件中的 宏的 顺序并没
有规定,但是 你必须在 所有宏的 最前面和最后面分别加上AC_INIT宏和AC_OUTPUT宏.
　　在 configure.ini中：
　　#号表示注释,这个宏后面的 内容将被忽略.
　　AC_INIT(FILE)
　　这个宏用来检查源代码所在 的 路径.
AM_INIT_AUTOMAKE(PACKAGE, VERSION)
　　 这个宏是 必须的 ,它描述了我们将要生成的 软件包的 名字及其版本号：PACKAGE是软件包
的名字,VERSION是 版本号.当你使用make dist命令时,它会给你生成一个类似
helloworld-1.0.tar.gz的 软件发行包,其中就有对应的 软件包的 名字和版本号.
AC_PROG_CC
　　这个宏将检查系统所用的 C编译器.
AC_OUTPUT(FILE)
　　这个宏是 我们要输出的 Makefile的 名字.
　　我们在 使用automake时,实际上还需要用到其他的 一些宏,但我们可以用aclocal 来帮
我们自动产生.执行aclocal后我们会得到aclocal.m4文件.
　　产生了configure.in和aclocal.m4 两个宏文件后,我们就可以使用autocon
f来产生configure文件了.
　　5. Makefile.am
　　Makefile.am是 用来生成Makefile.in的 ,需要你手工书写.Makefile.
am中定义了一些内容：
AUTOMAKE_OPTIONS
　　这个是 automake的 选项.在 执行automake时,它会检查目录下是 否存在 标准
GNU软件包中应具备的各种文件,例如AUTHORS.ChangeLog.NEWS等文件.
我们将其设置成foreign时,automake会改用一般软件包的 标准来检查.
bin_PROGRAMS
　　这个是 指定我们所要产生的 可执行文件的 文件名.如果你要产生多个可执行文件,
那么在各个名字间用空格隔开.
helloworld_SOURCES
　　这个是 指定产生"helloworld"时所需要的 源代码.如果它用到了多个源文件,
那么请使用空格符号将它们隔开.比如需要helloworld.h,helloworld.c那么请写成:
helloworld_SOURCES= helloworld.h helloworld.c.
　　如果你在 bin_PROGRAMS定义了多个可执行文件,则对应每个可执行文件都要定义相对的
filename_SOURCES.
　　6. automake
　　我们使用automake --add-missing来产生Makefile.in.
　　选项--add-missing的 定义是 "add missing standard files
 to package",它会让automake加入一个标准的 软件包所必须的 一些文件.
　　我们用automake产生出来的 Makefile.in文件是 符合GNU Makefile惯例
的 ,接下来我们只要执行configure这个shell 脚本就可以产生合适的 Makefile 文
件了.
　　7. Makefile
　　在 符合GNU Makefiel惯例的 Makefile中,包含了一些基本的 预先定义的 操作：

make
　　根据Makefile编译源代码,连接,生成目标文件,可执行文件.
make clean
　　清除上次的 make命令所产生的 object文件（后缀为".o"的 文件）及可执行文件.
make install
　　将编译成功的 可执行文件安装到系统目录中,一般为/usr/local/bin目录.
make dist
　　产生发布软件包文件（即distribution package）.这个命令将会将可执行文件及相关
文件打包成一个tar.gz压缩的 文件用来作为发布软件的 软件包.
　　它会在 当前目录下生成一个名字类似"PACKAGE-VERSION.tar.gz"的 文件.PA
CKAGE和VERSION,是 我们在 configure.in中定义的 AM_INIT_AUTOM
AKE(PACKAGE, VERSION).
make distcheck
　　生成发布软件包并对其进行测试检查,以确定发布包的正确性.
</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><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_c.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_sh.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_sh.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_sh.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_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/2009/11/18/1154.html" >2010/01/25</a>, Nathan writes: That's awesome!
It would be great help for me.</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><h2 class="related_post_title" >Random Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/08/16/301.html"  title="扩展PHP[Extending PHP](一)" >扩展PHP[Extending PHP](一)</a></li><li><a href="http://www.laruence.com/2007/12/16/308.html"  title="PHP:Header" >PHP:Header</a></li><li><a href="http://www.laruence.com/2008/09/19/520.html"  title="深入理解PHP原理之变量分离/引用(Variables Separation)" >深入理解PHP原理之变量分离/引用(Variables Separation)</a></li><li><a href="http://www.laruence.com/2008/11/20/640.html"  title="Opcodes list" >Opcodes list</a></li><li><a href="http://www.laruence.com/2009/02/21/662.html"  title="PHP字符串比较" >PHP字符串比较</a></li><li><a href="http://www.laruence.com/2008/08/12/164.html"  title="深入理解PHP原理之函数(Introspecting PHP Function)" >深入理解PHP原理之函数(Introspecting PHP Function)</a></li><li><a href="http://www.laruence.com/2010/02/03/1283.html"  title="Facebook性能大提升的秘密：HipHop" >Facebook性能大提升的秘密：HipHop</a></li><li><a href="http://www.laruence.com/2008/04/04/17.html"  title="在PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究" >在PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究</a></li><li><a href="http://www.laruence.com/2008/08/28/483.html"  title="HTTP1.0下HTTP_HOST为空" >HTTP1.0下HTTP_HOST为空</a></li><li><a href="http://www.laruence.com/2009/04/22/687.html"  title="谈谈用户可预感体验" >谈谈用户可预感体验</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/11/18/1154.html/feed</wfw:commentRss>
		<slash:comments>1</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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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" >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><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/09/28</a>, 网站推广 writes: <a href="http://www.powercordcn.com"  rel="nofollow" >power cord</a>网站利用半年时间采用了如下<a href="http://www.linkanywhere.net"  rel="nofollow" >网站推广</a>策略: URL优化。<a href="http:www.shendayumei.cn"  rel="nofollow" >

美容</a>网站不断优化URL,提高URL与推广内容的关联性。<a href="http:www.shendayumei.cn"  rel="nofollow" >护肤</a>例如

搜索“塑料产品”,在搜索页的URL中包含了关键词和搜索条件。 <a href="http://www.shiheng.com.cn"  rel="nofollow" >热敏

电阻</a>中小企业特别需要有诚意、有能力帮助<a href="http://www.inewbags.com"  rel="nofollow" >Louis Vuitton</a>中小

企业成长的专业人士长期深入到企业中识别挑战、<a href="http://www.bspv.cn/shui_9.html"  rel="nofollow" >离心泵</a>定

义问题、<a href="http://www.inewbags.com"  rel="nofollow" >Replica Louis Vuitton</a>剖析原因、<a href="http://www.cnjjyq.com"  rel="nofollow" >万能试验机</a>提出策略和解决方案.</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/09/29</a>, 纽约旅游租车 writes: 在<a href="http://www.gogogous.com"  rel="nofollow" >纽约旅游租车</a>:你可以享受一下汽车停下来为你让路的待遇。<a href="http://www.gogogous.com"  rel="nofollow" >纽约购物</a>这个待遇大家都知道,但是与跟着旅游团鱼贯而行的感受是不同的,<a href="http://www.gogogous.com"  rel="nofollow" >纽约机场接送</a>比如你独自一人时,发现让你过路的汽车乃是一重型大卡车(比坦克还重),大力士司机高踞在驾驶室里哀求般地请你先走。<a href="http://www.fc186.com/xwq.html"  rel="nofollow" >纤维球过滤器</a>你在国内患了汽车恐惧症,你大吃一惊:汽车居然停下来,让你先。你不知所措,不敢动,等着它怒按喇叭。<a href="http://www.fc186.com/yys.html"  rel="nofollow" >饮用水设备</a>对不起,汽车上的喇叭基本上没人用,都生锈了。汽车总是静悄悄地开,总在为它侵扰行人的世界而内疚着似的。司机在等你过街,你太不好意思了,装着并不过路的样子,<a href="http://www.gdweixing.net"  rel="nofollow" >广东卫星电视</a>等大卡车走掉,才猫着腰飞快溜过。如此几番,过大街就放开胆子了,<a href="http://www.gdweixing.net"  rel="nofollow" >广东卫星电视安装</a>汽车恐惧症不治而愈。<a href="http://www.gdweixing.net"  rel="nofollow" >广东安装卫星电视</a>看着排成一条龙的汽车恭候着你,你发现你不是什么过街老鼠,你乃步行之王。</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/10/19</a>, 气动隔膜泵 writes: <a href="http://www.bspv.cn/shui_7.html"  rel="nofollow" >气动隔膜泵</a>上海博生水泵制造有限公司系ISO9001-2000国际质量管理体系认证企业。<a href="http://www.bspv.cn/shui_1.html"  rel="nofollow" >磁力泵</a>由原上海长虹工业泵厂联合国内多家同行及引进外资组建而成的合资企业。产品广泛应用于市政建设、农田水利、<a href="http://www.lvshinet.net"  rel="nofollow" >上海房地产律师</a>火力发电、石油化工、冶金矿山、<a href="http://www.lvshinet.net"  rel="nofollow" >房产律师</a>消防环保、食品、航运、医药和轻纺等各个领域，<a href="http://www.akyb58.com/ProductShow.asp?ID=372"  rel="nofollow" >HART手操器</a>是中国水泵业协会和<a href="http://www.akyb58.com/ProductShow.asp?ID=327"  rel="nofollow" >压力变送器</a>全国水泵联销体两大组织的成员企业。<a href="http://www.bspv.cn/shui_10.html"  rel="nofollow" >螺杆泵</a> 水泵博生公司拥有一批专业技术精、<a href="http://www.lvshinet.net"  rel="nofollow" >上海房产律师</a>管理水平高的复合型人才.</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/10/27</a>, 竹纤维家纺 writes: 现代都市生活忙碌而紧张,一个<a href="http://www.zlytex.com"  rel="nofollow" >竹纤维家纺</a>温暖的家能带给每个人最放松的休闲时光，如果说 的发展顺应人们热爱健康、
<a href="http:www.shendayumei.cn"  rel="nofollow" >巴黎诗碧曼</a>注重环保的迫切需求;就是这样的一个品牌,看好 ,源于它 ,其推出的<a href="http://www.zlytex.com"  rel="nofollow" >竹纤维品牌</a>家纺产品绝对是符合市场消费需求的产品,<a href="www.shendayumei.cn"  rel="nofollow" >深大玉妹</a>符合追求健康时尚产品和生活品味的人们所要求的。2.<a href="http://www.fyjtjc.com"  rel="nofollow" >自动割管机</a>机械设备防寒过冬所需各种油料的储备工作,<a href="http://www.fyjtjc.com"  rel="nofollow" >自动割料机</a>及时更换各类机械发动机的润滑油和防冻液,检查调整蓄电池电解液的比重等;<a href="http://www.heyuanjx.com.cn/daishi.html"  rel="nofollow" >带式过滤机</a>对轨道车等进行彻底检查,严格按照要求做好<a href="http://www.heyuanjx.com.cn/daishi.html"  rel="nofollow" >橡胶带式过滤机</a>制动试验,确保制动性能良好。</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/11/15</a>, 金属管转子流量 writes: 几种常用<a href="http://www.flowmeterchina.com/detail_107.html"  rel="nofollow" >金属管转子流量计</a>的基础知识和比较，叶轮、<a href="http://www.flowmeterchina.com/detail_90.html"  rel="nofollow" >涡轮流量计</a>、活塞或孔板等用以分流流体。PD流量计的精确度较高,是测量粘性液体的几种方法之一。<a href="http://www.flowmeterchina.com/detail_106.html"  rel="nofollow" >齿轮流量计</a>像PD流量计,涡轮流量计也会产生不可恢复的压力误差,也需要移动部件。 电磁流量计 具有传导性的流体在流经电磁场时,通过测量电压可得到流体的速度；齐齐哈尔市旅游资源十分丰富,<a href="http://www.gogogous.com"  rel="nofollow" >波士顿旅游</a>素以生态环境良好,野生动物植物繁多,山水景色秀美,文化古迹奇特,冰雪风光绮丽而著称。<a href="http://www.gogogous.com"  rel="nofollow" >纽约购物</a>近年来,我市旅游产业有了长足的发展,<a href="http://www.intrade55.com"  rel="nofollow" >cheap handbags</a>已经成为国民经济的重要组成部分。特别是我市是少数民族聚集区域<a href="http://www.intrade55.com"  rel="nofollow" >NFL Jerseys</a>,民族地区的历史文化积淀深厚,自然资源<a href="http://www.kjqingxiji.com"  rel="nofollow" >超声波清洗机</a>、人文资源独具特色。</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/11/25</a>, 进口泵 writes: PS3 <a href="http://www.nb-qiaopu.com"  rel="nofollow" >power cord</a> Cyber Monday deals 2010 Best Buy Target &amp; More  ，<a href="http://www.powercordcn.com"  rel="nofollow" >power cord</a> the next generation of gaming with Nyko's Power Cord for PlayStation 3. The <a href="http://www.qiaopucord.com"  rel="nofollow" >power cord</a> fits into any standard wall outlet and works great as a；江苏大学海水淡化装置科研成果国际领先，<a href="http://www.yongbeikeji.cn"  rel="nofollow" >乳化机</a>国产高压泵样机一次开机成功,<a href="http://www.bansuochina.com"  rel="nofollow" >进口阀门</a>现场有一台国外进口泵也同时运行,经检测,在相同频率运行时,国产泵流量、<a href="http://www.yongbeikeji.cn"  rel="nofollow" >均质器</a>压力均高于进口泵,电机电流值低于进口泵,效率约为进口泵的1.11倍。<a href="http://www.bansuochina.com"  rel="nofollow" >进口水泵</a>这意味着一个日产万吨级的反渗透海水淡化装置,<a href="http://www.bansuochina.com"  rel="nofollow" >进口泵</a>如采用两台国产高压泵运行。</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2010/12/10</a>, Channel Magnets writes: 悬吊<a href="http://www.sensmag.com/products_27_Channel Magnets.html"  rel="nofollow" >Channel Magnets</a>地球仪 眼界超越局限尽在掌握,悬吊磁铁地球仪,仅仅是材质的变化,<a href="http://www.sensmag.com/products_33_Sensors Magnets.html"  rel="nofollow" >Sensors Magnets</a>就把地球仪的呆板一扫而空;深灰的金属色,富有时尚触觉。 <a href="http://www.sensmag.com/products_28_Other Magnetic Assembly.html"  rel="nofollow" >Other Magnetic Assembly</a>它可以通过磁铁吸附,挂在墙上成为立体的球型壁画,悬吊在天花板上作为装饰,或者只是简单摆放在桌上。<a href="http://www.shendayumei.cn"  rel="nofollow" >美白</a>重要的是,无论何时何地;桃皮绒销量不减 ,寒意日渐袭人,这一季适用于制作成夹克衫、<a href="http://www.intrade55.com"  rel="nofollow" >Nike air max</a>、休闲装的面料在市场上销量一直是相当不错,商家忙碌着向工厂下订单、<a href="http://www.intrade55.com"  rel="nofollow" >puma shoes</a>做货样、催出货。<a href="http://www.intrade55.com"  rel="nofollow" >cheap handbags</a>无论是内销订单,还是外贸订货,<a href="http://www.shendayumei.cn"  rel="nofollow" >护肤</a>桃皮绒在近期的盛泽市场上有其一定的地位,尤其深受东欧地区的客商喜欢。</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2011/04/14</a>, cute writes: http://wiki.nginx.org/HttpFcgiModule#.24fastcgi_script_name
fastcgi_split_path_info</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2011/11/17</a>, xiatian writes: location ~ .php {//片段匹配
光这样配置还是有风险,如果网站允许上传文件的话(比如图片),用户上传一个muma.php.jpg,该jpg文件内容为一个php木马,然后请求这个路径,如果php可以解析该目录里的文件的话,nginx会把它交给php解析执行,那木马就可以运行了,虽然有很多如果,但不注意可能性还很大.

对于框架来说好办,框架只访问index.php,所以只要nginx将php首页交给php处理.其他的php文件一律返回404好了.

nginx还新增了一个fastcgi_split_path_info参数用于获取PATH_INFO信息:
fastcgi_split_path_info ^(/index\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;</li><li><a href="http://www.laruence.com/2009/11/13/1138.html" >2011/11/18</a>, <a href="http://www.ijser.cn/?p=623"  rel="external nofollow"  class="url" >Nginx(PHP/fastcgi)的PATH_INFO问题 » ijser</a> writes: [...] 本文地址: http://www.laruence.com/2009/11/13/1138.html [...]</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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/01/20/1247.html"  title="Nginx/PHP Fastcgi PATH_INFO的一个问题" >Nginx/PHP Fastcgi PATH_INFO的一个问题</a></li><li><a href="http://www.laruence.com/2010/05/20/1495.html"  title="Nginx + PHP CGI的一个可能的安全漏洞" >Nginx + PHP CGI的一个可能的安全漏洞</a></li><li><a href="http://www.laruence.com/2012/02/02/2515.html"  title="我们什么时候应该使用异常?" >我们什么时候应该使用异常?</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2012/01/11/2482.html"  title="PHP的历史" >PHP的历史</a></li><li><a href="http://www.laruence.com/2012/01/10/2469.html"  title="如何设置一个严格30分钟过期的Session" >如何设置一个严格30分钟过期的Session</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  title="PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/11/13/1138.html/feed</wfw:commentRss>
		<slash:comments>28</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" >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" >2009/07/28</a>, xi2008wang writes: 现在都用php-fpm代替spawn-cgi了</li><li><a href="http://www.laruence.com/2009/07/28/1030.html" >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" >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" >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" >2009/07/31</a>, weimade writes: 手册里也有。。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html" >2009/08/01</a>, zhangyufeng writes: 前一阵我也搭了一个，感觉最困难的是nginx的rewrite规则……能不能写写这方面……网上很多支离破碎的文章。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html" >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" >2009/08/07</a>, zhangyufeng writes: 手册上讲的是如何使用，而我想清楚的是如何用的更好……呵呵，想学习一下前辈的经验。</li><li><a href="http://www.laruence.com/2009/07/28/1030.html" >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" >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" >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" >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/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/12/14/1816.html"  rel="bookmark"  title="Permanent Link: Compilation failed: support for P, p, and X has not been compiled" >Compilation failed: support for P, p, and X has not been compiled</a></li><li><a href="http://www.laruence.com/2009/11/27/1164.html"  rel="bookmark"  title="Permanent Link: memory_limit的一个bug" >memory_limit的一个bug</a></li><li><a href="http://www.laruence.com/2011/07/16/2123.html"  rel="bookmark"  title="Permanent Link: 浏览器多tab打开同一URL串行化的问题" >浏览器多tab打开同一URL串行化的问题</a></li><li><a href="http://www.laruence.com/2010/11/02/1789.html"  rel="bookmark"  title="Permanent Link: [转载]技术文化和惨淡命运 —— 怀念中国雅虎" >[转载]技术文化和惨淡命运 —— 怀念中国雅虎</a></li><li><a href="http://www.laruence.com/2011/05/05/2002.html"  rel="bookmark"  title="Permanent Link: Apache Access Log中的Options的含义" >Apache Access Log中的Options的含义</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/01/20/1247.html"  title="Nginx/PHP Fastcgi PATH_INFO的一个问题" >Nginx/PHP Fastcgi PATH_INFO的一个问题</a></li><li><a href="http://www.laruence.com/2010/05/20/1495.html"  title="Nginx + PHP CGI的一个可能的安全漏洞" >Nginx + PHP CGI的一个可能的安全漏洞</a></li><li><a href="http://www.laruence.com/2009/11/13/1138.html"  title="Nginx(PHP/fastcgi)的PATH_INFO问题 " >Nginx(PHP/fastcgi)的PATH_INFO问题 </a></li></ul>]]></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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >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" >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" >2009/04/21</a>, zhangYufeng writes: 收藏，呵呵。</li><li><a href="http://www.laruence.com/2009/04/21/680.html" >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" >2010/08/26</a>, Ssfds writes: sfdsfdsfd</li><li><a href="http://www.laruence.com/2009/04/21/680.html" >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" >2010/09/08</a>, Eric writes: 不错，学习了，可惜我们公司的代码注释的不太规范，无法生成文档了。。。</li><li><a href="http://www.laruence.com/2009/04/21/680.html" >2011/11/30</a>, <a href="http://liuxd.blog.chinaunix.net"  rel="external nofollow"  class="url" >Liuxd</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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2012/02/02/2515.html"  title="我们什么时候应该使用异常?" >我们什么时候应该使用异常?</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2012/01/11/2482.html"  title="PHP的历史" >PHP的历史</a></li><li><a href="http://www.laruence.com/2012/01/10/2469.html"  title="如何设置一个严格30分钟过期的Session" >如何设置一个严格30分钟过期的Session</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  title="PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2011/12/06/2381.html"  title="更简单的重现PHP Core的调用栈" >更简单的重现PHP Core的调用栈</a></li><li><a href="http://www.laruence.com/2011/11/18/2305.html"  title="GBK编码PHP脚本导致语法错误(Zend Multibyte)" >GBK编码PHP脚本导致语法错误(Zend Multibyte)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/04/21/680.html/feed</wfw:commentRss>
		<slash:comments>8</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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >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" >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" >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" >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" >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" >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" >2008/08/26</a>, chinawolfs writes: 
执行这样应该不会有什么问题的.顺序的情况</li><li><a href="http://www.laruence.com/2008/08/24/427.html" >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><li><a href="http://www.laruence.com/2008/08/24/427.html" >2010/09/29</a>, 好消息 writes: 好消息1.纵观社会的发展方向,<a href="http://www.hendrex.com.cn/main/20081289304942/Page/201041221543012/"  rel="nofollow" >火花机</a>行业拥有良好的发展趋势,并且已经成为一个传统而又崭新的创业领域。<a href="http://www.hendrex.com.cn/main/20081289304942/page/2010541721323/"  rel="nofollow" >上海加工中心</a>目前,随着我国经济的快速发展,对<a href="http://www.hendrex.com.cn/main/20081289304942/page/20105170525484/"  rel="nofollow" >苏州火花机</a>机械行业的加大了重视度,尤其是矿山机械。随着近几年,砂石冶金等行业生产规模的扩大,<a href="http://www.hendrex.com.cn"  rel="nofollow" >加工中心维修</a>其对人工机制砂的需求越来越大：2.秋季美容<a href="http://www.shendayumei.cn"  rel="nofollow" >护肤</a>:水嫩不干燥 <a href="http://www.shendayumei.cn"  rel="nofollow" >美容</a>秋季护理大，简要内容:爱美女性往往会过多关心面部的青春娇美,却易忽视自己颈部的保养。<a href="http://www.nj4006.com"  rel="nofollow" >400</a>尤其是在干燥的秋季,颈部皮肤容易老化,粗糙无光、松弛多皱。<a href="http://www.zjhuanbao.com.cn"  rel="nofollow" >浙江环保设备采购</a>每天晚上洗浴时,用含碱少的温和型香皂洗涤颈部,<a href="http://dt.wx35.com"  rel="nofollow" >江苏墙体广告</a>用松软毛巾擦干,再进行按摩。</li><li><a href="http://www.laruence.com/2008/08/24/427.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=152"  rel="external nofollow"  class="url" >PHP5多层继承顺序的bug | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2008/08/24/427.html [...]</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/05/28/1565.html"  rel="bookmark"  title="Permanent Link: PHP错误抑制符(@)导致引用传参失败的Bug" >PHP错误抑制符(@)导致引用传参失败的Bug</a></li><li><a href="http://www.laruence.com/2011/03/29/1949.html"  rel="bookmark"  title="Permanent Link: 深入理解PHP原理之Session Gc的一个小概率Notice" >深入理解PHP原理之Session Gc的一个小概率Notice</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  rel="bookmark"  title="Permanent Link: PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li><li><a href="http://www.laruence.com/2010/09/27/1754.html"  rel="bookmark"  title="Permanent Link: PHP stream未能及时清理现场导致Core的bug" >PHP stream未能及时清理现场导致Core的bug</a></li><li><a href="http://www.laruence.com/2008/09/20/523.html"  rel="bookmark"  title="Permanent Link: PHP5.3 α2初体验" >PHP5.3 α2初体验</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/03/22/1929.html"  title="PHP Reflection Extension的一个bug" >PHP Reflection Extension的一个bug</a></li><li><a href="http://www.laruence.com/2010/05/28/1565.html"  title="PHP错误抑制符(@)导致引用传参失败的Bug" >PHP错误抑制符(@)导致引用传参失败的Bug</a></li><li><a href="http://www.laruence.com/2010/05/26/1541.html"  title="PHP类型转换相关的一个Bug" >PHP类型转换相关的一个Bug</a></li><li><a href="http://www.laruence.com/2009/12/05/1172.html"  title="PHP5.2.x + APC的一个bug的定位" >PHP5.2.x + APC的一个bug的定位</a></li><li><a href="http://www.laruence.com/2012/02/02/2515.html"  title="我们什么时候应该使用异常?" >我们什么时候应该使用异常?</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2012/01/11/2482.html"  title="PHP的历史" >PHP的历史</a></li><li><a href="http://www.laruence.com/2012/01/10/2469.html"  title="如何设置一个严格30分钟过期的Session" >如何设置一个严格30分钟过期的Session</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  title="PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/08/24/427.html/feed</wfw:commentRss>
		<slash:comments>10</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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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://laruence-wordpress.stor.sinaapp.com/uploads/zend_engine.png" ><img src="http://laruence-wordpress.stor.sinaapp.com/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" >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" >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" >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" >2008/08/13</a>, yongtao.pang writes: 看zval去啦，有人劈荆斩棘真好</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >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" >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" >2008/08/23</a>, Leftwater writes: 决定长期阅读学习博主文章~</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2008/08/24</a>, liexusong writes: 你出PHP内核的书的话，我一定买！！</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >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" >2008/09/08</a>, sue writes: 传说中的“右手诗”在哪里啊。。</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2008/10/13</a>, highjade writes: 学习~</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >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" >2008/12/07</a>, guangtianxia writes: 支持这种精神。</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >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" >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" >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" >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" >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" >2010/05/15</a>, phper writes: 博主的文章写得太好了！偶像,我要长期关注</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2010/05/28</a>, 人海孤鸿 writes: 赞</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >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" >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" >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" >2010/08/26</a>, xiaobao writes: 上面那张图对吗，鸟哥？
require或者函数是编译的时候一并编译了，还是等到执行的时候，再回头去编译？好像应该是前者吧。</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2011/03/11</a>, <a href="http://blog.bjmayor.com/?p=138"  rel="external nofollow"  class="url" >怪异的js编码问题 | bjmayor的个人空间</a> writes: [...] 深入浅出PHP(Exploring PHP) [...]</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=186"  rel="external nofollow"  class="url" >深入浅出PHP(Exploring PHP) | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2008/08/11/147.html [...]</li><li><a href="http://www.laruence.com/2008/08/11/147.html" >2011/09/02</a>, <a href="http://warpigallen.sinaapp.com/?p=9"  rel="external nofollow"  class="url" >深入浅出PHP(Exploring PHP) | warpig_allen&#039;s blog</a> writes: [...] 本文地址: http://www.laruence.com/2008/08/11/147.html [...]</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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/09/23/539.html"  title="使用PHP Embed SAPI实现Opcodes查看器" >使用PHP Embed SAPI实现Opcodes查看器</a></li><li><a href="http://www.laruence.com/2008/09/19/520.html"  title="深入理解PHP原理之变量分离/引用(Variables Separation)" >深入理解PHP原理之变量分离/引用(Variables Separation)</a></li><li><a href="http://www.laruence.com/2008/08/26/463.html"  title="深入理解PHP原理之变量作用域(Scope in PHP)" >深入理解PHP原理之变量作用域(Scope in PHP)</a></li><li><a href="http://www.laruence.com/2008/08/22/412.html"  title="深入理解PHP原理之变量(Variables inside PHP)" >深入理解PHP原理之变量(Variables inside PHP)</a></li><li><a href="http://www.laruence.com/2008/08/15/274.html"  title="PHP 源代码分析 V0.0.2" >PHP 源代码分析 V0.0.2</a></li><li><a href="http://www.laruence.com/2008/08/14/250.html"  title="实现PHP的编译执行分离(separating compilation and execution)" >实现PHP的编译执行分离(separating compilation and execution)</a></li><li><a href="http://www.laruence.com/2008/08/12/180.html"  title="深入理解Zend SAPIs(Zend SAPI Internals)" >深入理解Zend SAPIs(Zend SAPI Internals)</a></li><li><a href="http://www.laruence.com/2008/08/12/164.html"  title="深入理解PHP原理之函数(Introspecting PHP Function)" >深入理解PHP原理之函数(Introspecting PHP Function)</a></li><li><a href="http://www.laruence.com/2008/06/18/221.html"  title="深入理解PHP原理之Opcodes" >深入理解PHP原理之Opcodes</a></li><li><a href="http://www.laruence.com/2007/12/16/308.html"  title="PHP:Header" >PHP:Header</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/08/11/147.html/feed</wfw:commentRss>
		<slash:comments>27</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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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/><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/07/24/206.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=188"  rel="external nofollow"  class="url" >Apache启动过程(PHP_MINIT_FUNCTION的调用) | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2008/07/24/206.html [...]</li></ul><hr/><h2>Related posts:</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/10/26/1768.html"  rel="bookmark"  title="Permanent Link: AllowEncodedSlashes in Apache" >AllowEncodedSlashes in Apache</a></li><li><a href="http://www.laruence.com/2008/08/22/389.html"  rel="bookmark"  title="Permanent Link: Apache主导全美100大网站" >Apache主导全美100大网站</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  rel="bookmark"  title="Permanent Link: 通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2011/05/05/2002.html"  rel="bookmark"  title="Permanent Link: Apache Access Log中的Options的含义" >Apache Access Log中的Options的含义</a></li><li><a href="http://www.laruence.com/2011/02/13/1870.html"  rel="bookmark"  title="Permanent Link: 加速PHP的ECHO" >加速PHP的ECHO</a></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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2012/02/02/2515.html"  title="我们什么时候应该使用异常?" >我们什么时候应该使用异常?</a></li><li><a href="http://www.laruence.com/2012/02/01/2503.html"  title="使用exit(-1)为什么得到255退出码?" >使用exit(-1)为什么得到255退出码?</a></li><li><a href="http://www.laruence.com/2012/01/11/2482.html"  title="PHP的历史" >PHP的历史</a></li><li><a href="http://www.laruence.com/2012/01/10/2469.html"  title="如何设置一个严格30分钟过期的Session" >如何设置一个严格30分钟过期的Session</a></li><li><a href="http://www.laruence.com/2012/01/07/2453.html"  title="2012年1月全球www网站技术报告" >2012年1月全球www网站技术报告</a></li><li><a href="http://www.laruence.com/2011/12/30/2440.html"  title="PHP5.2.*防止Hash冲突拒绝服务攻击的Patch" >PHP5.2.*防止Hash冲突拒绝服务攻击的Patch</a></li><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/12/06/2381.html"  title="更简单的重现PHP Core的调用栈" >更简单的重现PHP Core的调用栈</a></li><li><a href="http://www.laruence.com/2011/11/18/2305.html"  title="GBK编码PHP脚本导致语法错误(Zend Multibyte)" >GBK编码PHP脚本导致语法错误(Zend Multibyte)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/07/24/206.html/feed</wfw:commentRss>
		<slash:comments>1</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[Linux/Unix]]></category>
		<category><![CDATA[PHP Extension]]></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>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >2008/09/25</a>, fy writes: 《Aapache源码分析》??</li><li><a href="http://www.laruence.com/2008/04/09/112.html" >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" >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" >2010/05/20</a>, whut_avatar writes: 请指教，小弟先表示谢意！</li><li><a href="http://www.laruence.com/2008/04/09/112.html" >2010/05/20</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @whut_avatar 不好意思, N年前搞的了, 现在对这块已经不熟悉了, 爱莫能助.</li><li><a href="http://www.laruence.com/2008/04/09/112.html" >2011/05/10</a>, Ricky 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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2008/04/16/19.html"  title="编写提供对象给PHP使用的Module" >编写提供对象给PHP使用的Module</a></li><li><a href="http://www.laruence.com/2011/12/29/2412.html"  title="通过构造Hash冲突实现各种语言的拒绝服务攻击" >通过构造Hash冲突实现各种语言的拒绝服务攻击</a></li><li><a href="http://www.laruence.com/2011/05/05/2002.html"  title="Apache Access Log中的Options的含义" >Apache Access Log中的Options的含义</a></li><li><a href="http://www.laruence.com/2010/10/26/1768.html"  title="AllowEncodedSlashes in Apache" >AllowEncodedSlashes in Apache</a></li><li><a href="http://www.laruence.com/2008/07/24/206.html"  title="Apache启动过程(PHP_MINIT_FUNCTION的调用)" >Apache启动过程(PHP_MINIT_FUNCTION的调用)</a></li><li><a href="http://www.laruence.com/2008/04/17/110.html"  title="页面乱码问题根源浅析" >页面乱码问题根源浅析</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2008/04/09/112.html/feed</wfw:commentRss>
		<slash:comments>6</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/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; [...]]]></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" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></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>转载请注明出处 </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" >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><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2010/08/18/1718.html"  title="将PHP Manual融入(g)Vim" >将PHP Manual融入(g)Vim</a></li><li><a href="http://www.laruence.com/2010/04/17/1433.html"  title="用Vim写Blog" >用Vim写Blog</a></li><li><a href="http://www.laruence.com/2008/05/01/106.html"  title="汉字和Unicode码(utf-8)之间的转换(Pack/Unpack)" >汉字和Unicode码(utf-8)之间的转换(Pack/Unpack)</a></li><li><a href="http://www.laruence.com/2008/04/17/110.html"  title="页面乱码问题根源浅析" >页面乱码问题根源浅析</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2007/10/03/5.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

