<?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的comet 代码]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 06 Aug 2009 10:55:09 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	下载：<br/><a href="attachment.php?fid=17">点击这里下载文件</a><br/>你可以开多个浏览器IE，FIREFOX等来测试,你也可以通过它来进行两个远在天边的人来聊天：<br/>点击：<a href="http://www.5ifd.com/comet" target="_blank">http://www.5ifd.com/comet</a><br/><br/><br/><div class="code">&lt;?php<br/><br/>$filename&nbsp;&nbsp;= dirname(__FILE__).&#039;/data.txt&#039;;<br/><br/>// store new message in the file<br/>$msg = isset($_GET&#91;&#039;msg&#039;&#93;) ? $_GET&#91;&#039;msg&#039;&#93; : &#039;&#039;;<br/>if ($msg != &#039;&#039;)<br/>&#123;<br/>&nbsp;&nbsp;file_put_contents($filename,$msg);<br/>&nbsp;&nbsp;die();<br/>&#125;<br/><br/>// infinite loop until the data file is not modified<br/>$lastmodif&nbsp;&nbsp;&nbsp;&nbsp;= isset($_GET&#91;&#039;timestamp&#039;&#93;) ? $_GET&#91;&#039;timestamp&#039;&#93; : 0;<br/>$currentmodif = filemtime($filename);<br/>while ($currentmodif &lt;= $lastmodif) // check if the data file has been modified<br/>&#123;<br/>&nbsp;&nbsp;usleep(10000); // sleep 10ms to unload the CPU<br/>&nbsp;&nbsp;clearstatcache();<br/>&nbsp;&nbsp;$currentmodif = filemtime($filename);<br/>&#125;<br/><br/>// return a json array<br/>$response = array();<br/>$response&#91;&#039;msg&#039;&#93;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = file_get_contents($filename);<br/>$response&#91;&#039;timestamp&#039;&#93; = $currentmodif;<br/>echo json_encode($response);<br/>flush();<br/><br/>?&gt;</div><br/><br/><div class="code"><br/>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot; &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;<br/>&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br/>&nbsp;&nbsp;&lt;head&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Comet demo&lt;/title&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;script type=&quot;text/javascript&quot; src=&quot;prototype.js&quot;&gt;&lt;/script&gt;<br/>&nbsp;&nbsp;&lt;/head&gt;<br/>&nbsp;&nbsp;&lt;body&gt;<br/><br/>&lt;div id=&quot;content&quot;&gt;<br/>&lt;/div&gt;<br/><br/>&lt;p&gt;<br/>&nbsp;&nbsp;&lt;form action=&quot;&quot; method=&quot;get&quot; onsubmit=&quot;comet.doRequest($(&#039;word&#039;).value);$(&#039;word&#039;).value=&#039;&#039;;return false;&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;text&quot; name=&quot;word&quot; id=&quot;word&quot; value=&quot;&quot; /&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Send&quot; /&gt;<br/>&nbsp;&nbsp;&lt;/form&gt;<br/>&lt;/p&gt;<br/><br/>&lt;script type=&quot;text/javascript&quot;&gt;<br/>var Comet = Class.create();<br/>Comet.prototype = &#123;<br/><br/>&nbsp;&nbsp;timestamp: 0,<br/>&nbsp;&nbsp;url: &#039;./backend.php&#039;,<br/>&nbsp;&nbsp;noerror: true,<br/><br/>&nbsp;&nbsp;initialize: function() &#123; &#125;,<br/><br/>&nbsp;&nbsp;connect: function()<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.ajax = new Ajax.Request(this.url, &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: &#039;get&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters: &#123; &#039;timestamp&#039; : this.timestamp &#125;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function(transport) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// handle the server response<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var response = transport.responseText.evalJSON();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.comet.timestamp = response&#91;&#039;timestamp&#039;&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.comet.handleResponse(response);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.comet.noerror = true;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete: function(transport) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// send a new ajax request when this request is finished<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!this.comet.noerror)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// if a connection problem occurs, try to reconnect each 5 seconds<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setTimeout(function()&#123; comet.connect() &#125;, 5000); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.comet.connect();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.comet.noerror = false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.ajax.comet = this;<br/>&nbsp;&nbsp;&#125;,<br/><br/>&nbsp;&nbsp;disconnect: function()<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&#125;,<br/><br/>&nbsp;&nbsp;handleResponse: function(response)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$(&#039;content&#039;).innerHTML += &#039;&lt;div&gt;&#039; + response&#91;&#039;msg&#039;&#93; + &#039;&lt;/div&gt;&#039;;<br/>&nbsp;&nbsp;&#125;,<br/><br/>&nbsp;&nbsp;doRequest: function(request)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;new Ajax.Request(this.url, &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: &#039;get&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters: &#123; &#039;msg&#039; : request &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;);<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>var comet = new Comet();<br/>comet.connect();<br/>&lt;/script&gt;<br/><br/>&lt;/body&gt;<br/>&lt;/html&gt;<br/><br/></div><br/><br/>prototype.js<br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP的comet 代码]]></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>