简体   繁体   English

Node.js和socket.io用于通知栏:我是否正确行事?

[英]Node.js and socket.io for a notification bar : Am I going the right way?

I'm currently coding a quite standard Apache/PHP/mySQL website using Symfony2 and considering using Node and socket.io for a special need : a notification bar. 我目前正在使用Symfony2编写一个非常标准的Apache / PHP / mySQL网站,并考虑使用Node和socket.io来满足特殊需求:通知栏。 Nothing too fancy, a notification is lit when you've got a new friend request, a new mail... 没有什么太花哨的,当你收到新的朋友请求时,通知会被点亮,新邮件......

I'm not too fond of periodically requesting my DB from an ajax loop; 我不太喜欢周期性地从ajax循环请求我的数据库; I'd like this feature to be fully scalable and to have a minimal footprint. 我希望这个功能完全可扩展,占用空间最小。

Thus I'm considering having a single periodical request on my DB, server-side, feeding my list of open sockets in Node with a push notification to each concerned user. 因此,我正在考虑在我的数据库(服务器端)上发出一个定期请求,在Node中提供我的开放套接字列表,并向每个相关用户发送推送通知。

Am I going the right way ? 我走对了路吗?

Cheers 干杯

You're definitely on the right track, but I suggest putting the notification stuff in your app, rather than polling your database. 你肯定是在正确的轨道上,但我建议将通知内容放在你的应用程序中,而不是轮询你的数据库。 For example of friend request, do it when the friend request is sent: 例如好友请求,请在发送好友请求时执行:

function send_friend_request($from, $to) {
    $mysqli->whatever you do with that;
    send_notification($to, 'You have a friend request!');
}

where send_notification is a method that sends a POST request to your nodejs server. 其中send_notification是一种向您的nodejs服务器发送POST请求的方法。 Your nodejs server receives the POST and forwards the message to whatever is listening to $to . 您的nodejs服务器接收POST并将消息转发给正在侦听$to任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM