I'm looking to get my mind round node.js...
I'm happy with my Light setup because it presently fulfils my needs. Although I wish to then add real-time features into my PHP application. For example showing all customers presently drenched into my website and possible chat features.
I'd rather not replace my PHP after sales, however i do want scalable real-time solutions.
1. Can One throw node.js in to the mix for everyone me without repairing the entire application server-side script?
2. Just how could node.js serve my 'chat' and 'currently drenched in' features?
Great to listen to your sights!
It is best to use Socket.io with node.js. Install and download the libs from http://socket.io/. You are able to run it with your Apache server no problems.
First produce a node server:
var http = require('http') , url = require('url') , fs = require('fs') , io = require('../')//road to your socket.io lib , sys = require(process.binding('natives').util ? 'util' : 'sys') , server server = http.createServer(function(req, res)), server.listen(8084)//This may be just about any port number
Second, run your server in the command line using:
Third, connect with the socket using client side js:
var socket = new io.Socket(null, ) socket.connect()
You'll have to have range from the socket.io lib client side aswell.
Send data from client side towards the node server using:
Your server.js also needs to have functions for processing demands:
io.on('connection', function(client)transmits monosodium glutamate ) client.on('disconnect', function()) )
You will find two primary methods to send data in the server towards the client:
client.send()//transmits it to the customer making the request
client.broadcast()//transmits it too every client attached to the server
I suspect the chat along with the drenched in listing works via Ajax.
The chat part could be pretty simple to enter in Node.js, use among the mysql modules for Node for connecting for your existing database and query login information and the like after which do all of the actual talking via Node.js, I suggest you to look at Socket.io because it makes Browser/Node.js communcation really trivial, this will permit you to target the actual chat logic.
Also, you can have a look in the "official" chat demo of Node.js, for many inspiration.
So far as the presently online part goes, this really is never simple to apply since all you should do is to show something like "5 customers mixed up in last X minutes".
Obviously you can easily then add Ajax that queries the chat server and display the userlist from that around the home page.
Or else you completely crazy and begin a Socket.io connection for each customer and monitor it by doing this, although it's questionable whether this really is well worth the effort.
How about utilizing a socket file much like pedro did with ngnx ? http://nodetuts.com/lessons/25-nginx-and-nodejs.html