我使用Ajax-php-xml技術創建了聊天應用程序。如果用戶數量低於50,那麼它工作正常。否則,應用程序的速度急劇下降。我想一次管理200個用戶。如何提高Ajax-php-xml聊天應用程序的速度?
我的XML格式是
<?xml version="1.0" encoding="utf-8"?>
<messageData>
<message>
<sender>user__5338</sender>
<receiver>user__5339</receiver>
<content>hello</content>
<date_time>2012-08-17 09:24:57</date_time>
<status>unread</status>
</message>
<message>
<sender>user__5338</sender>
<receiver>user__5339</receiver>
<content>hello</content>
<date_time>2012-08-17 09:26:21</date_time>
<status>unread</status>
</message>
</messageData>
在我的php,我用這個方法
$xml = simplexml_load_file($this->xml_file);
foreach($xml->message as $chat_data){
if($chat_data->status =='unread' && $chat_data->receiver ==$username){
$chat_data->status = 'read';
$xml->asXML($this->xml_file);
$sender =(string)$chat_data->sender;
$chat['message'] = (string)$chat_data->content;
$chat['date'] = (string)$chat_data->date_time;
}
}
如何聊天次數增加應用程序的速度獲取從XML文件中的數據?我可以通過使用節點js來提高速度嗎?
AJAX是不是真的適合這一類的事情,至少最佳。 Web套接字的實現更復雜,但可能值得研究。他們是爲這種事情設計的。 – Utkanos 2012-08-17 10:40:56