<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[PHP+shell实现多线程]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Mon, 06 Oct 2008 06:11:35 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	看到这个标题，大家可能要说我没常识，php根本不支持多线程啊，没错，php本身是不支持多线程，但是别忘了php的好搭档，apache和linux可是支持的，呵呵，lamp才是最佳组合，还在使用win服务器的现在知道为什么要用linux吧？好久没在phpchina说教了，今天水一帖，写个简单的代码演示下如何借助shell脚本实现多线程。<br/><br/>先写个简单的php代码，这里为了让脚本执行时间更长，方便看效果，sleep一下，呵呵！先看下test.php的代码： 复制PHP内容到剪贴板 <br/>PHP代码:<br/><br/><div class="code">&lt;?php<br/>for ($i=0;$i&lt;10;$i++) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo $i;<br/>&nbsp;&nbsp;&nbsp;&nbsp;sleep(10);<br/>&#125;<br/>?&gt;</div><br/><br/>在看下shell脚本的代码，非常简单 复制内容到剪贴板 <br/>代码:<br/><br/><br/><div class="code">#!/bin/bash<br/>for i in 1 2 3 4 5 6 7 8 9 10<br/>do<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;php -q ./thread.php &amp;<br/>done</div><br/>注意到在请求php代码的那行有一个&amp;符号吗，这个是关键，不加的话是不能进行多线程的，&amp;表示讲服务推送到后台执行，因此，在shell的每次的循环中不必等php的代码全部执行完在请求下一个文件，而是同时进行的，这样就实现了多线程，下面运行下shell看下效果，这里你将看到10个test.php进程再跑，再利用linux的定时器，定时请求这个shell，在处理一些需要多线程的任务，例如，批量下载时，非常好用！<br/>结果出现：<br/><br/><div class="code">0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999</div><br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP+shell实现多线程]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>