AJAX 即时通讯
你好,我正在尝试制作一个 AJAX 即时通讯工具。我目前有一个使用 PHP、MySql、Java Script 等的网站(带有用户登录、管理区域等)和一个带有 2 个聊天室(以及房间列表中的用户等)的 AJAX 聊天程序,它工作得很好,但不太了解从这里去哪里(即时通讯工具)。我做了一些研究,建议使用 AJAX 监听器来接收新消息,但我找不到太多关于它的信息......或者如果确实需要这样做,或者我应该使用其他东西。如果有人对我下一步应该去哪里有任何建议,我将非常非常感激,谢谢:)
Hi I am trying to make an AJAX instant messenger. I currently have a website (with user logon, admin area etc.) using PHP, MySql, Java Script etc and an AJAX chat prog with 2 chat rooms (and users in room list etc) and it works really good, but dont really know where to go from here (instant messenger wise). I have done some researh which has suggested using an AJAX listener for new messages but I cant find much information on it...or if indeed this is needed or i should use something else. If anyone has any advice where I should go next it would be very, very much appreciated, thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用流中心。反向 AJAX - 非常酷的东西
Use Stream Hub. Reverse AJAX - pretty cool stuff
你可以试试Dojo基金会的cometd!
http://cometd.org/
You can try cometd of Dojo Foundation!
http://cometd.org/
Node.js
就像很多人提到的那样,我会使用 node.js/socket.io 而不是 PHP。它的创建就是为了解决此类问题。
Redis
但如果你真的想在 PHP 中创建类似的东西,我会使用 redis(需要安装)。它具有阻止列表操作,可以真正帮助您创建类似的东西。当某个用户向另一个用户发送消息时,我们推送该消息到相应的阻止列表该用户的。用户通过监听唯一的阻止列表(键)来接收消息。
无法安装Redis
然后你必须使用MySQL频繁插入表和轮询表,但不要太多而杀死你的服务器/数据库。
Node.js
Like a lot of people mentioned I would use node.js/socket.io for this instead of PHP. It has been created to tackle such sort of problems.
Redis
But if you really want to create somethink like this in PHP I would do it using redis(needs to be installed). It has blocking list operations which really help you create something like this. When some user sents a message to another user we push the message to corresponding blocking list of that user. The user listens to an unique blocking list(key) to receive messages.
Can not install Redis
Then you have to use MySQL insert into a table and poll table frequently, but not to much to kill your server/database.
对于需要实时和立即响应的聊天或类似聊天的应用程序,node.js 可能是一种选择。提到的 socket.io 也是基于 Node.js 构建的。它可以在服务器端和客户端上使用。
有很多关于 Node.js 的博客/教程。或者您可能会喜欢这个,即使它需要一点费用。
For a chat or chat-like application which needs realtime and immediate responses probably node.js is a way to go. The mentioned socket.io is also built on node.js. It can be used both on server and client side.
There are lot of blogs/tutorials about node.js. Or you may like this, even if it is for a little fee.
我建议您访问 www.socket.io 了解实时信息。
IIRC 网站上甚至还有一个即时通讯示例。
I'd suggest taking a look at www.socket.io for the real-time stuff.
There's even an instant messenger example on the site IIRC.
为什么不选择像 AJAX Chat 这样的东西,它是免费且开源的!
我想这可能会让你继续前进!
Why dont you go with something like AJAX Chat, it's free and open source!
I think it might get you going!