同时向多个用户广播通知 - PHP / MySql / Ajax

时间:2022-10-28 21:40:48

I'm new to the forum, any advise is appreciated I've search a lot and read and read a lot of topics to find the best way for my project I'll get straight to the point

我是新来的论坛,任何建议都表示赞赏我经常搜索并阅读和阅读很多主题以找到我项目的最佳方式我会直截了当地说到这一点

I'm building a Broadcast site to be used internally at work using wamp server (intranet).

我正在使用wamp服务器(intranet)构建一个在工作中内部使用的广播站点。

Languages used: PHP, JS, Ajax, MySql

使用的语言:PHP,JS,Ajax,MySql

For the moment we are using a chat system (spark), but the idea of the project is to keep broadcasts records and it's easier to track

目前我们正在使用聊天系统(火花),但该项目的想法是保持广播记录,并且更容易跟踪

Please don't offer me Third party applications/tools

请不要向我提供第三方应用程序/工具

I have a simple html form that a user submit info, consider this example.

我有一个简单的html表单,用户提交信息,请考虑此示例。

Form: title (input text field), Broadcast message(input text field)

表格:标题(输入文本字段),广播消息(输入文本字段)

Info stored in the db table:

存储在db表中的信息:

bc_id, title, bc_msg, submitted_by, date_time

bc_id,title,bc_msg,submitted_by,date_time

Another table user_got_bc: user_id, bc_id, bc_sent (0 default), once notification is sent, the value is 1

另一个表user_got_bc:user_id,bc_id,bc_sent(默认值为0),一旦发送通知,值为1

I'm using ajax to look in the "user_got_bc" table and verify which user has the bc_sent = 0 and send a notification to him with the bc info from the other table, then update the value of the bc_sent to 1

我正在使用ajax查看“user_got_bc”表并验证哪个用户具有bc_sent = 0并使用来自另一个表的bc信息向他发送通知,然后将bc_sent的值更新为1

The ajax code is executed every 10000 ms using setinterveral

使用setinterveral每10000毫秒执行ajax代码

once a user submit a broadcast I want all other USERS (PLURAL) to receive a notification AT THE SAME TIME (a second less or more is ok)

一旦用户提交广播,我希望所有其他用户(PLURAL)在相同时间接收通知(少于或多于一秒)

Now regarding the Notification, you don't have to worry about that, i'm using Desktop notification (webkitnotification), I know it's not cross browser compatible, but it doesn't matter and it's working fine

现在关于通知,你不必担心,我正在使用桌面通知(webkitnotification),我知道它不是跨浏览器兼容的,但它没关系,它工作正常

That said, everything is working fine

也就是说,一切正常

My worries are the number of connections the ajax code will do to the server if this good or bad, the more the users, the more the connections

我担心的是ajax代码对服务器的连接数如果好坏,用户越多,连接越多

I know it won't be good to bombard the server with that amount of connections, specially since it's every 10 secs x the number of users

我知道用这么多连接轰炸服务器是不好的,特别是因为它是每10秒x用户数量

I read on many forums to use comets, from what i gathered it's not friendly with PHP, plus i've never implemented that before

我在许多论坛上看到使用彗星,从我收集的它不友好的PHP,加上我从来没有实现过

So my questions are: - is there a better way or keep it the way is set up is fine? - if comets is better, is it possible to provide a snippet to work for that project?

所以我的问题是: - 是否有更好的方法或保持方式设置是好的? - 如果彗星更好,是否有可能为该项目提供一个片段?

Thanks all in advance.

提前谢谢。

1 个解决方案

#1


0  

Please google for Ajax long polling. But for this kind of project i suggest using some realtime i/o software like

请谷歌搜索Ajax长轮询。但对于这种项目,我建议使用一些实时的i / o软件

node.js and socket.io

node.js和socket.io

If you have good JavaScript skills then you should not have problem in using above listed apps. If your project is going to have more number of users then you will require PUB-SUB, Realtime, Cross Browser Socket support. Finally a PUSH technology. Where above listed apps have all this features. So give a try.

如果你有很好的JavaScript技能,那么你应该在使用上面列出的应用程序时遇到问题。如果您的项目将拥有更多用户,那么您将需要PUB-SUB,实时,跨浏览器套接字支持。最后是PUSH技术。上面列出的应用程序具有所有这些功能。所以试一试。

If you still want to stick to PHP, JS, Ajax, MySql then you may require Ajax long polling technique.

如果您仍然想要坚持使用PHP,JS,Ajax,MySql,那么您可能需要使用Ajax长轮询技术。

#1


0  

Please google for Ajax long polling. But for this kind of project i suggest using some realtime i/o software like

请谷歌搜索Ajax长轮询。但对于这种项目,我建议使用一些实时的i / o软件

node.js and socket.io

node.js和socket.io

If you have good JavaScript skills then you should not have problem in using above listed apps. If your project is going to have more number of users then you will require PUB-SUB, Realtime, Cross Browser Socket support. Finally a PUSH technology. Where above listed apps have all this features. So give a try.

如果你有很好的JavaScript技能,那么你应该在使用上面列出的应用程序时遇到问题。如果您的项目将拥有更多用户,那么您将需要PUB-SUB,实时,跨浏览器套接字支持。最后是PUSH技术。上面列出的应用程序具有所有这些功能。所以试一试。

If you still want to stick to PHP, JS, Ajax, MySql then you may require Ajax long polling technique.

如果您仍然想要坚持使用PHP,JS,Ajax,MySql,那么您可能需要使用Ajax长轮询技术。