实时新消息通知 [英] live new message notification

查看:135
本文介绍了实时新消息通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我们为网站用户提供了一个消息框系统,我想做的是,如果将新消息发送给成员,而目标成员在其收件箱中,则他可以看到一条通知消息.他收到新消息后.

Imagine we're having a message box system for our website users, what I want to do is that if a new message is sent to a member, while the targeted member is on his inbox, he could see a notification message right after he gets the new message.

为此,我们可以使用"new_messages" div,该div将使用带有setInterval()的jQuery刷新并发送查询以查看是否有新消息,但是如果我们有10.000个成员,则不能发送10.000个查询,这可能会杀死服务器!!!我希望仅在hi收到新消息时才显示针对目标成员的通知.这样的事情我们可以在页面中有一个"listen" div,它会在触发新消息时被触发.

For having this, we could have the "new_messages" div which is gonna refresh using jQuery with setInterval() and sends the query to see if there is a new message or not, but if we have 10.000 members, we can not send 10.000 queries, this could just kill the server!!! I want a notification to be shown for the targeted member only when hi gets a new message. something like that we could have a "listen" div in our page, it gets fired when the new message is triggered.

我也已经了解了MySQL触发器,但是看来这不是解决方案,因为这可能会向数据库触发另一条SQL语句,而无助于向用户显示通知.

I've also read about the MySQL trigger, but it seems that's not gonna be a solution to this since that just could fire another SQL statement to the DB and not helping showing a notification to the user.

那么这种情况下的解决方案是什么?

So what's the solution for such scenario?

预先感谢

推荐答案

您可以查看 PHP Comet系统询问有关将实时事件从服务器推送到浏览器的想法.或者尝试研究使用Websockets的详细信息.但是,使用PHP并不能很好地解决这些问题.

You could look at PHP Comet system question for ideas on pushing live events from the server to the browser. Or try looking into the details of using Websockets as well. But these don't really go down well with PHP.

但是,如果您希望实现某种形式的聊天,请尝试查看 http://www.phpfreechat.net/

But if you looking to implement some kind of a chat try looking at http://www.phpfreechat.net/

这篇关于实时新消息通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆