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

<channel>
	<title>风雪之隅 &#187; 多进程</title>
	<atom:link href="http://www.laruence.com/tag/%e5%a4%9a%e8%bf%9b%e7%a8%8b/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +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>Mpass &#8211; PHP做Socket服务的解决方案</title>
		<link>http://www.laruence.com/2010/10/29/1774.html</link>
		<comments>http://www.laruence.com/2010/10/29/1774.html#comments</comments>
		<pubDate>Fri, 29 Oct 2010 08:27:14 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[后台服务]]></category>
		<category><![CDATA[多进程]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1774</guid>
		<description><![CDATA[  一般很少有用PHP做服务的, 但是如果你的已有业务逻辑都是PHP实现的, 而现在却需要基于已有的业务逻辑提供一套Socket服务, 怎么办?

  当然, 解决方法很多, 但最简单的办法, 还是直接使用PHP做Socket服务. 

  而这样做要解决的问题有很多, 主要要解决的问题有如下几个:
<coolcode lang="php" linenum="off">
1. 作为后台服务,需要常驻后台运行, 那么丁点的内存泄露都是不能接受的.
2. 作为后台服务,畸形数据导致进程异常退出, 也是不可接受的.
3. 作为后台服务, 要能做到graceful restart.
4. 作为后台服务, 对资源的使用必须在可接受的范围以内. 
</coolcode>

   最近,我就基于PHP写一个简单的提供Socket服务的框架. 取其名为Mpass(Multi-Processes Socket Server). ]]></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/10/29/1774.html"  title="Permanet Link to Mpass &#8211; PHP做Socket服务的解决方案" >http://www.laruence.com/2010/10/29/1774.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
  一般很少有用PHP做服务的, 但是如果你的已有业务逻辑都是PHP实现的, 而现在却需要基于已有的业务逻辑提供一套Socket服务, 怎么办?</p>
<p>  当然, 解决方法很多, 但最简单的办法, 还是直接使用PHP做Socket服务. </p>
<p>  而这样做要解决的问题有很多, 主要要解决的问题有如下几个:</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;">
1. 作为后台服务,需要常驻后台运行, 那么丁点的内存泄露都是不能接受的.
2. 作为后台服务,畸形数据导致进程异常退出, 也是不可接受的.
3. 作为后台服务, 要能做到graceful restart.
4. 作为后台服务, 对资源的使用必须在可接受的范围以内.
</pre>
<p>   最近,我就基于PHP的pcntl扩展实现一个简单的提供Socket服务的框架. 取其名为Mpass(Multi-Processes Socket Server). </p>
<p>   主要结构如下:<br/>
   <div id="attachment_1775"  class="wp-caption aligncenter"  style="width: 509px" ><a href="http://laruence-wordpress.stor.sinaapp.com/uploads/Mpass.png" ><img src="http://laruence-wordpress.stor.sinaapp.com/uploads/Mpass1.png"  alt=""  title="Mpass"  width="499"  height="255"  class="size-full wp-image-1775" /></a><p class="wp-caption-text" >Mpass</p></div></p>
<p>   我之前的文章<a href="http://www.laruence.com/2009/06/11/930.html" >PHP CLI模式下的多进程应用</a>介绍过在PHP做服务的时候如何避免内存泄露, 所以基于此, 再加上PHP5以后的stream_socket_*系列API, 就完成了这一套框架.</p>
<p>   至于Graceful restart, 通过pcntl_signal函数, 在接受到restart/shutdown信号时刻, 做关闭清理动作, 保证不会因为重启/关闭而使得正在执行的逻辑出错.</p>
<p>   有类似需求的朋友, 可以借鉴. </p>
<p>   <b>项目地址&#038;下载地址</b> : <a href="http://code.google.com/p/mpass/downloads/list"  target="_blank" >Mpass</a><br/>
   <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/2010/10/29/1774.html" >2010/10/29</a>, 张二 writes: 哈哈，一楼哦，狂顶一下。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/10/29</a>, Once writes: 鸟哥V5!</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/10/29</a>, <a href="http://www.xinqdian.com"  rel="external nofollow"  class="url" >灵气</a> writes: 脚本语言做守护还是很轻巧的。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/10/29</a>, <a href="http://zhg.me"  rel="external nofollow"  class="url" >hfcorriez</a> writes: 期待中...</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/10/29</a>, <a href="http://www.mrcody.com"  rel="external nofollow"  class="url" >baikaizhlg</a> writes: 鸟哥威武！！</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/10/29</a>, sharmy writes: 太威武了，我手里的项目正在为这个东西头疼，在想要不要用c++做接口，看看这个再说。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/01</a>, <a href="http://www.lookme.jp/"  rel="external nofollow"  class="url" >蘑菇姐姐</a> writes: 顶一下。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/03</a>, <a href="http://blog.fj18.com"  rel="external nofollow"  class="url" >grom</a> writes: 我想了解一下这个框架性能如何，支持并发量多少？
过几天跟进看看。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/07</a>, <a href="http://syre.blogbus.com"  rel="external nofollow"  class="url" >神仙</a> writes: 我倒是用libevent扩展做过一个服务。
pcntl就用来变daemon了。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/08</a>, <a href="http://blog.danotes.com/2010/11/08/mpass-%e2%80%93-php%e5%81%9asocket%e6%9c%8d%e5%8a%a1%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88.html"  rel="external nofollow"  class="url" >Mpass – PHP做Socket服务的解决方案 &raquo; NoNZero&#39;s Blog</a> writes: [...] 本文地址: http://www.laruence.com/2010/10/29/1774.html [...]</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/09</a>, <a href="http://www.iskycloud.com/blog/language/php/33.html"  rel="external nofollow"  class="url" >Mpass &ndash; PHP做Socket服务的解决方案 | 路漫漫其修远兮</a> writes: [...] 作者: laruence 原文地址：http://www.laruence.com/2010/10/29/1774.html [...]</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/11/09</a>, <a href="http://www.iskycloud.com/blog/language/php/34.html"  rel="external nofollow"  class="url" >PHP WebService得到通讯的SOAP包内容 | 路漫漫其修远兮</a> writes: [...] 本文地址: http://www.laruence.com/2010/10/29/1774.html [...]</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2010/12/09</a>, xi writes: 如何避免内存泄露
从后台程序的框架上讲，分两方面。
一方面，考虑资源的完整释放。这个如果加载了业务代码，风险变得不可控。
所以另一方面，考虑补救方法，当碰到意外的时候，如果处理意外。

个人认为，work进程运行一次就退出，有点性能问题，一般设计运行次数，来解决。

这样，listen进程到work进程的消息传递也是要考虑的。

呵呵，php cli做server。是OK的。
实际项目中有运用，空载来说的话，基本可以达到，c server的平均水平。</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2011/01/27</a>, <a href="http://www.132cc.com/724.html"  rel="external nofollow"  class="url" >132CC.com &raquo; Blog Archive &raquo; Mpass – PHP做Socket服务的解决方案</a> writes: [...] 本文地址: http://www.laruence.com/2010/10/29/1774.html [...]</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2011/01/27</a>, <a href="http://www.132cc.com/891.html"  rel="external nofollow"  class="url" >132CC.com &raquo; Blog Archive &raquo; 又一个PHP低概率Core的分析(PHP内存管理)</a> writes: [...] Mpass &#8211; PHP做Socket服务的解决方案  Copyright &copy; 2010 风雪之隅 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2) [...]</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2011/03/09</a>, <a href="http://xiao3.org"  rel="external nofollow"  class="url" >小桑</a> writes: 我想问下博主你那结构图用神马工具做的....</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2011/03/09</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @小桑 xmind</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2011/11/07</a>, xiongrui888 writes: 拜读了您的相关文章，很是钦佩，有一事想请教您，我用php做了一个socket服务端，但这个服务端怎么不能持久运行，一般只能运行几个小时。怎么才能保证这个服务端的一直运行呢？</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2012/01/07</a>, Sunyanzi writes: 雪候鸟大牛好 ...

我现在在实现一个多进程 socket server ... 所以 mpass 肯定是必看的一个东西 ...

我注意到您在 mpass 里面使用 stream_socket_create 来创建一个 socket server ...

我想问一下这种方式和使用 socket_create / socket_bind / socket_bind 这个方式有什么区别么 ..?

我要实现的是 socket 不停接收另外一个 server 传过来的指令 ...

指令的处理时间可能很长 ... 所以需要交由子进程完成 ...

在这样的情境下使用哪种方式创建我的 socket server 会比较合适呢 ..?

恩就是这样 ... 谢谢 ...</li><li><a href="http://www.laruence.com/2010/10/29/1774.html" >2012/01/07</a>, Sunyanzi writes: 上文最后一个 socket_bind 应该是 socket_listen ...

勘误 ... 我紧张了我 ... &gt;&lt;</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/09/04/1736.html"  rel="bookmark"  title="Permanent Link: Yaf-一个PHP扩展实现的PHP框架" >Yaf-一个PHP扩展实现的PHP框架</a></li><li><a href="http://www.laruence.com/2011/03/24/858.html"  rel="bookmark"  title="Permanent Link: 一些PHP Coding Tips[2011/04/02最后更新]" >一些PHP Coding Tips[2011/04/02最后更新]</a></li><li><a href="http://www.laruence.com/2011/01/27/1854.html"  rel="bookmark"  title="Permanent Link: 深入理解PHP内存管理之一个低概率Core的分析" >深入理解PHP内存管理之一个低概率Core的分析</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/2009/06/11/930.html"  title="PHP CLI模式下的多进程应用" >PHP CLI模式下的多进程应用</a></li><li><a href="http://www.laruence.com/2012/02/08/2528.html"  title="PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)" >PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)</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/2010/10/29/1774.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>PHP CLI模式下的多进程应用</title>
		<link>http://www.laruence.com/2009/06/11/930.html</link>
		<comments>http://www.laruence.com/2009/06/11/930.html#comments</comments>
		<pubDate>Thu, 11 Jun 2009 06:48:36 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[muti process]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php多进程]]></category>
		<category><![CDATA[多进程]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=930</guid>
		<description><![CDATA[    PHP在很多时候不适合做常驻的SHELl进程, 他没有专门的gc例程, 也没有有效的内存管理途径.  所以如果用PHP做常驻SHELL, 你会经常被内存耗尽导致abort而unhappy.
   
    而且, 如果输入数据非法, 而SHELL没有检测, 导致abort, 也会让你很不开心.

    那? 怎么办呢?
 
    多进程....]]></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/06/11/930.html"  title="Permanet Link to PHP CLI模式下的多进程应用" >http://www.laruence.com/2009/06/11/930.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
    PHP在很多时候不适合做常驻的SHELL进程, 他没有专门的gc例程, 也没有有效的内存管理途径.  所以如果用PHP做常驻SHELL, 你会经常被内存耗尽导致abort而unhappy.</p>
<p>    而且, 如果输入数据非法, 而脚本没有检测, 导致abort, 也会让你很不开心.</p>
<p>    那? 怎么办呢?</p>
<p>    多进程&#8230;.
</p>
<p>
   <strong> 为什么呢?</strong></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. 使用多进程,子进程异常退出不会导致整个进程Thread退出. 父进程还有机会重建流程.
    3. 一个常驻主进程, 只负责任务分发, 逻辑更清楚.
</pre>
</p>
<p>
<strong> Then, 怎么做呢? </strong></p>
<p>    接下来, 我们使用PHP提供的POSIX和Pcntl系列函数, 来实现一个PHP命令解析器, 主进程负责接受用户输入, 然后fork子进程执行, 并负责回显子进程的结束状态.</p>
<p>   代码如下, 我加了注释, 如果有不懂的地方, 可以翻阅手册相关函数, 或者<a href="http://www.laruence.com/2009/06/11/930.html#comment"  title="风雪之隅" >回复</a>留言.</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;">
#!/bin/env php
&lt;?php
/** A example denoted muti-process application in php
 * @filename fork.php
 * @touch date Wed 10 Jun 2009 10:25:51 PM CST
 * @author Laruence&lt;laruence@baidu.com&gt;
 * @license http://www.zend.com/license/3_0.txt   PHP License 3.0
 * @version 1.0.0
*/

/** 确保这个函数只能运行在SHELL中 */
if (substr(php_sapi_name(), 0, 3) !== 'cli') {
    die(&quot;This Programe can only be run in CLI mode&quot;);
}

/**  关闭最大执行时间限制, 在CLI模式下, 这个语句其实不必要 */
set_time_limit(0);

$pid  = posix_getpid(); //取得主进程ID
$user = posix_getlogin(); //取得用户名

echo &lt;&lt;&lt;EOD
USAGE: [command | expression]
input php code to execute by fork a new process
input quit to exit

        Shell Executor version 1.0.0 by laruence
EOD;

while (true) {

        $prompt = &quot;\n{$user}$ &quot;;
        $input  = readline($prompt);

        readline_add_history($input);
        if ($input == 'quit') {
			break;
		}
        process_execute($input . ';');
}

exit(0);

function process_execute($input) {
        $pid = pcntl_fork(); //创建子进程
        if ($pid == 0) {//子进程
                $pid = posix_getpid();
                echo &quot;* Process {$pid} was created, and Executed:\n\n&quot;;
                eval($input); //解析命令
                exit;
        } else {//主进程
                $pid = pcntl_wait($status, WUNTRACED); //取得子进程结束状态
                if (pcntl_wifexited($status)) {
                        echo &quot;\n\n* Sub process: {$pid} exited with {$status}&quot;;
                }
        }
}
   </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;">
Process Control should not be enabled within a webserver environment and unexpected results may happen if any Process Control functions are used within a webserver environment.  --摘自PHP手册
</pre>
<p>  <strong>也就是说, 打消你在PHP Web开发中使用多进程的念头吧! </strong>
</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_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/06/11/930.html" >2009/07/16</a>, <a href="http://www.3avon.cn"  rel="external nofollow"  class="url" >如何化妆</a> writes: 很实用</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2009/07/18</a>, <a href="http://www.zhouxblog.com"  rel="external nofollow"  class="url" >zhoushine</a> writes: 我们这边有个类似系统就是用php去做的。怕gc有问题。子进程处理一定数量的请求后就退了重新fork出来。</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2009/07/20</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: 恩,PHP的GC,我搞到现在了还没完全搞清楚..释放的时机,释放的深度等等...</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/07/16</a>, jackyd writes: 这篇介绍5.3GC的文章貌似不错：
http://blog.csdn.net/phpkernel/archive/2010/07/14/5734743.aspx</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/10/29</a>, <a href="http://www.laruence.com/2010/10/29/1774.html"  rel="external nofollow"  class="url" >Mpass &#8211; PHP做Socket服务的解决方案 | 风雪之隅</a> writes: [...] 我之前的文章PHP CLI模式下的多进程应用介绍过在PHP做服务的时候如何避免内存泄露, 所以基于此, 再加上PHP5以后的stream_socket_*系列API, 就完成了这一套框架. [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/10/29</a>, <a href="http://zhg.me"  rel="external nofollow"  class="url" >hfcorriez</a> writes: 学习，这个也只能在后台事务处理上用用。</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/11/08</a>, <a href="http://blog.danotes.com/2010/11/08/php-cli%e6%a8%a1%e5%bc%8f%e4%b8%8b%e7%9a%84%e5%a4%9a%e8%bf%9b%e7%a8%8b%e5%ba%94%e7%94%a8.html"  rel="external nofollow"  class="url" >PHP CLI模式下的多进程应用 &raquo; NoNZero&#39;s Blog</a> writes: [...] 代码如下, 我加了注释, 如果有不懂的地方, 可以翻阅手册相关函数, 或者回复留言. [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/11/08</a>, <a href="http://blog.danotes.com/2010/11/08/mpass-%e2%80%93-php%e5%81%9asocket%e6%9c%8d%e5%8a%a1%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88.html"  rel="external nofollow"  class="url" >Mpass – PHP做Socket服务的解决方案 &raquo; NoNZero&#39;s Blog</a> writes: [...] 我之前的文章PHP CLI模式下的多进程应用介绍过在PHP做服务的时候如何避免内存泄露, 所以基于此, 再加上PHP5以后的stream_socket_*系列API, 就完成了这一套框架. [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2010/12/01</a>, <a href="http://www.iskycloud.com/blog/language/php/33.html"  rel="external nofollow"  class="url" >Mpass &ndash; PHP做Socket服务的解决方案 | 天道酬勤</a> writes: [...] 我之前的文章PHP CLI模式下的多进程应用介绍过在PHP做服务的时候如何避免内存泄露, 所以基于此, 再加上PHP5以后的stream_socket_*系列API, 就完成了这一套框架. [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=223"  rel="external nofollow"  class="url" >PHP CLI模式下的多进程应用 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2009/06/11/930.html [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2011/04/16</a>, <a href="http://www.wjmboss.cn/?p=1474"  rel="external nofollow"  class="url" >PHP CLI模式下的多进程应用 | Jim的blog</a> writes: [...] 代码如下, 我加了注释, 如果有不懂的地方, 可以翻阅手册相关函数, 或者回复留言. [...]</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2011/05/11</a>, <a href="http://blog.tuohuang.net"  rel="external nofollow"  class="url" >拓荒.net</a> writes: 我将源码拷贝运行测试，居然提示process_execute()未定义，我不得不把定一此函数的function process_execute()这段话放到调用之前，才能正常运行，不知道为什么……</li><li><a href="http://www.laruence.com/2009/06/11/930.html" >2011/10/09</a>, evoup writes: php -r 可以吗？常驻shell啥意思</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/10/29/1774.html"  title="Mpass &#8211; PHP做Socket服务的解决方案" >Mpass &#8211; PHP做Socket服务的解决方案</a></li><li><a href="http://www.laruence.com/2012/02/08/2528.html"  title="PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)" >PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830)</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/06/11/930.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

