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. 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; 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.
Am I going the right way ?
Cheers
In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .
Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server. It is built on top of the WebSocket protocol and provides additional guarantees like fallback to HTTP long-polling or automatic reconnection.
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. Your nodejs server receives the POST and forwards the message to whatever is listening to $to
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With