考慮使用像PubNub這樣的服務。你不需要擔心NodeJS或者websockets。將PubNub插入PHP和你的前端,你就會全部設置好。
下面是教程的摘要版本在這裏找到的文本: http://www.pubnub.com/blog/php-push-api-walkthrough/
JavaScript的PHP的推式API的「Hello World」
這PHP代碼將消息發送到一個JavaScript瀏覽器在'my_test_channel'頻道上收聽。當此PHP代碼執行時,JavaScript瀏覽器將收到PHP數組並顯示「hello!」警報消息。
## Publish Messages To a JavaScript Browser
$pubnub = new Pubnub('publish_key', 'subscribe_key');
$pubnub->publish(array(
'channel' => 'my_test_channel',
'message' => array('some_text' => 'hello!')
));
上面的JavaScript是完全跨瀏覽器兼容的。該代碼將監聽'my_test_channel'頻道上發佈的消息。收到消息時,JavaScript會驗證消息對象中是否存在'some_text'。如果此屬性存在,則顯示一個警報框!
PUBNUB.subscribe({ channel : 'my_test_channel' },
function(message) {
if ('some_text' in message) {
alert(message.some_text);
}
});
谷歌發現這個:http://socket.io/ – 2013-05-01 07:05:19