<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/post/311/</link>
<title><![CDATA[PHP多进程并发控制的测试用例[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[PHP/JS/Shell]]></category>
<pubDate>Fri, 16 Nov 2007 06:32:30 +0000</pubDate> 
<guid>http://zyan.cc/post/311/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.0 最后修改：2007.11.16 转载请注明出处：<a href="http://blog.zyan.cc" target="_blank">http://blog.zyan.cc</a>]<br/><br/>　　最近遇到一个问题，Linux下的PHP命令行程序作为守护进程，需要从队列文件中读一行数据，通过TCP协议发送给外地的接收服务器，再读下一行数据，再发送。当本地与外地的网络状况不好时，有时候发送一条数据所耗费的时间就较长，累积起来容易造成队列堵塞和延迟。<br/><br/>　　于是，我准备用该PHP命令行程序生成多个子进程，将串行处理变成并行处理。最简单的方法就是在PHP中用exec()或popen()函数将一个shell命令行推到后台去执行，例如：<div class="code">&lt;?php<br/>exec(&quot;/bin/sh /opt/zhangyan.sh &amp;&quot;);<br/>?&gt;</div>　　最后的&表示将shell脚本推到后台去执行。<br/><br/>　　但是这样会有一个问题，如果推到后台的进程太多，可能会导致服务器系统资源耗尽而崩溃，所以必须控制进程数量。<br/><br/><hr/><br/>　　我写了一个PHP程序（/opt/zhangyan.php）、一个shell程序（/opt/zhangyan.sh）作为测试用例。<br/><br/>　　<strong>程序的逻辑：</strong><br/>　　1、设置/opt/zhangyan.php最多允许生成500个子进程；<br/>　　2、当/opt/zhangyan.php读取到一条数据后，将允许生成的子进程数减1（空闲进程数$p_number=500-1=499），然后将数据交给/opt/zhangyan.sh去后台处理，不等待/opt/zhangyan.sh处理结束，继续读取下一条数据；<br/>　　3、当允许生成的子进程数减至0时（空闲进程数$p_number=0），/opt/zhangyan.php会等待1秒钟，然后检查后台还有多少个/opt/zhangyan.sh子进程尚未处理结束；<br/>　　4、如果1秒钟之后/opt/zhangyan.php发现后台的/opt/zhangyan.sh子进程数还是500（空闲进程数$p_number=0），会继续等待1秒钟，如此反复；<br/>　　5、如果/opt/zhangyan.php发现后台尚未处理结束的/opt/zhangyan.sh子进程数减少到300个了（空闲进程数$p_number=500-300=200），那么/opt/zhangyan.php会再往后台推送200个/opt/zhangyan.sh子进程；<br/><br/>............<br/><br/>Tags - <a href="http://zyan.cc/tags/linux/" rel="tag">linux</a> , <a href="http://zyan.cc/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment458</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>劲草 &lt;liucomcn@163.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 16 Nov 2007 06:53:01 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment458</guid> 
<description>
<![CDATA[ 
	很好，很强大，<br/>很喜欢你的程序。。。尤其是APMServ。<br/>不过遗憾的是你的APMServ到2.0版就没动静了呀。<br/>现在PHP5出了5.2.5了，修改了很多Bug。。<br/>MySQL也出了5.0的新版了，应该会有改进吧。。<br/>Apache貌似也更新了一些东东。。。<br/>不知道你是否会把APMServ继续更新下去，期待你的新作。。。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment459</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>pdo &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 16 Nov 2007 08:46:53 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment459</guid> 
<description>
<![CDATA[ 
	博主你使用什么数据库啊?<br/>想用您哪个编译的方法安装带PDO和PDO_ibm的nginx服务器，不知道如何下手。<br/><br/>可否抽空实验一下啊？<br/><br/>感谢
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment460</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>APM用户 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 17 Nov 2007 02:52:09 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment460</guid> 
<description>
<![CDATA[ 
	建议你先出个过渡版本的APMServ，把Apache、PHP5、MySQL，phpMyAdmin等模块更新至最新版本，至于APMServ.exe这个程序如果没时间的话，那些尚未完成的功能在以后再添加。<br/>毕竟新版的Apache、PHP5、MySQL修补了很多的漏洞和Bug。<br/>个人愚见，希望你考虑一下。。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment624</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>水草萍 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 25 Jan 2008 05:00:28 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment624</guid> 
<description>
<![CDATA[ 
	博主尝试过stream_select()吗？据说可以实现进程的并发。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment1094</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>projector &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 26 May 2008 17:33:17 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment1094</guid> 
<description>
<![CDATA[ 
	进程内实现事件驱动模型可以很好的解决这个问题。<br/>fastcgi的工作机制就是那样。<br/><br/>当然现在的解决方法非常的简洁，不过也容易出现问题，呵呵。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment4437</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>niniwzw &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 17 Nov 2009 08:15:41 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment4437</guid> 
<description>
<![CDATA[ 
	我觉得用 纯PHP的解决方案 pcntl 控制线程更加的完美。<br/>最好，不要每次启动一个进程，然后关闭一个进程。让500个进程常驻内存进行发送，<br/>但是，这样的话，可能控制并发比较麻烦点。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment7026</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>Mr.cuix &lt;Mr.cuix@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 21 Oct 2010 03:37:08 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment7026</guid> 
<description>
<![CDATA[ 
	张大哥 我做了一个php来执行 .sh脚本，但是通过php来执行.sh脚本会产生一个假死进程，而在服务器上执行该.sh脚本是没问题的php 是用nobody权限nobody 已经在 /etc/sudoers 中添加了.sh脚本中所要执行的程序目录。不知是怎么回事了
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment7417</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>yong &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 07 Dec 2010 03:07:04 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment7417</guid> 
<description>
<![CDATA[ 
	你好，请教一下：可以用php 来执行 php 脚本吗？也就是把你的zhangyan.sh&nbsp;&nbsp;用一个php 的脚本zhangyan.php代替？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment7643</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>hh &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 17 Jan 2011 10:36:40 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment7643</guid> 
<description>
<![CDATA[ 
	可以，使用exec
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment18842</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>coach factory outlet &lt;fgf@hotmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 17 May 2012 03:15:12 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment18842</guid> 
<description>
<![CDATA[ 
	Today, following half a century, mentor leather-bases <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory outlet</a> continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory online</a> is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our <a href="http://www.coachfactoryoutletao.net" target="_blank">coach factory outlet online</a> store to choose one.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment18843</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>louis vuitton sale &lt;fgf@hotmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 17 May 2012 03:15:19 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment18843</guid> 
<description>
<![CDATA[ 
	Louis Vuitton belt at <a href="http://www.louisvuittonoutletsalea.com" target="_blank">louis vuitton sale</a> is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, <a href="http://www.louisvuittonoutletsalea.com" target="_blank">louis vuitton outlet</a> store is at your service. Hurry up, or you can not seize the chance.in fact, <a href="http://www.louisvuittonoutletsalea.com" target="_blank">louis vuitton</a> is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment18844</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>coach outlet online &lt;fgf@hotmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 17 May 2012 03:15:25 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment18844</guid> 
<description>
<![CDATA[ 
	I heard of <a href="http://www.coachoutletonlineao.net" target="_blank">coach outlet online</a> through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be <a href="http://www.coachoutletonlineao.net" target="_blank">coach outlet store</a>.<a href="http://www.coachoutletonlineao.net" target="_blank">coach outlet</a> has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment18845</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>coach outlet, &lt;fgf@hotmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 17 May 2012 03:15:35 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment18845</guid> 
<description>
<![CDATA[ 
	Remember the <a href="http://www.coachoutletin.org" target="_blank">coach outlet</a> provide coach bags which won&#039;t be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.<a href="http://www.coachoutletin.org" target="_blank">coach outlet store online</a> has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers&#039;poll.Lots of women like which usually amount normally include a <a href="http://www.coachoutletin.org" target="_blank">coach outlet online</a> ,it provides coziness to many girls that don&#039;t even think it is a great bushel of great interest directly to them.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment20048</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>xujie777 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 18 May 2012 08:35:17 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment20048</guid> 
<description>
<![CDATA[ 
	We aim to make all our customers satisfy with our products. You will find a variety of Men&#039;s fashion <a href="http://www.louisvuittonukd.org.uk" target="_blank">louis vuitton uk</a>, fashion Women&#039;s cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? <a href="http://www.louisvuittonukd.org.uk" target="_blank">louis vuitton online shop</a> had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment <a href="http://www.louisvuittonukd.org.uk" target="_blank">louis vuitton online</a> Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/311/#blogcomment20049</link>
<title><![CDATA[[评论] PHP多进程并发控制的测试用例[原创]]]></title> 
<author>xujie777 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 18 May 2012 08:35:25 +0000</pubDate> 
<guid>http://zyan.cc/post/311/#blogcomment20049</guid> 
<description>
<![CDATA[ 
	The choices are likely to be basically countless seeing that <a href="http://www.louisvuittonoutletbagsa.net" target="_blank">louis vuitton outlet</a> occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags <a href="http://www.louisvuittonoutletbagsa.net" target="_blank">louis vuitton bags outlet</a> Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the <a href="http://www.louisvuittonoutletbagsa.net" target="_blank">louis vuitton handbags outlet</a>.
]]>
</description>
</item>
</channel>
</rss>