NODEJS /socketio/ ELEPHANTIO working example
What i've made so far is a solution where the ajaxChat.php emits messages to the nodeserver that in turn notifies the affected sockets to update their chat.
It's nothing more than replacing the chatupdate that otherwise is handled by the timerrate in the config.js.
So the clients will only request data from the chat if ajaxchat thinks they should be informed.
First of all you should have a VPS or better. On shared hosting it’ll not be able to install and run!
The server needs
nodejs to be installed and running with socketio (npm)installed.. I have 0.10.35-1nodesource1~wheezy1 running.
You’ll need
elephantio (i have the latest version) for the communication between the php (Ajaxchat.php) and the Nodejsserver.
Use the directions supplied by
elephantio that uses the composer to install the sourcefiles in your chat.
I put mine in the lib dir. The folder created is vendor. The include at the top of ajaxChat.php points to the autoloader.php in that folder.
In the classes.php the required classes for elephantio also point to a dir in the vendorfolder.
To much editing on the files to make a comprehensive howto:
You can compare docs next to oneother e..g.
http://www.diffnow.com/The documents edited are:
chat.js
AjaxChat.php
Classes.php
loggedIn.html (scriptlink to js for the socketio.js) You can also use a cdn for it.
the files config.php and config.js should have socketserverenabled to true with sockethost and port.
(i had trouble passing the host from the config.js to chat.js and had to fill in the url and port in chat.js)
The server.js file is the one that runs as the server on nodejs. It’s in the socketdir of the tar attached.
The server.js is the file that receives messages in json from ajaxChat.php and the client connect to and receive notifications from.
You should carefully look at the code to see if i did'nt make any mistakes but i'm pretty confident that it works in a clean and fresh copy of the standalone087.
Perhaps it would be wise to make exeptionhandlers i the server.js?
I'm moving on now to bring it to my own chat that i'm still building. With the knowledge i gained so far scalability is not to worry about anymore. :-)