PHP replacement for socket.io
socket.io
. Easy to use, but
powerful and customizable. An essential addition to your development toolbox.
PHP 5.3+
You need to start the server from the commandline and not from inside the browser.
$: php server/server.phpFrom linux, you may want to use: nohup php server/server.php
Before running the php server, you need to configure the port to run the socket installation on inside socketio.php
$server_port="2000";
$socket->on('chat message', function ($socket,$data,$sender) { $socket->broadcast('chat message', $data,true); })
The above code is a server event that occurs when a message is sent from the client. The message is broadcasted to everyone.
var socket=$.websocket('ws://162.144.68.201:2000'); $('form').submit(function() { socket.emit('chat message', $('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('
When creating a connection to a server, you need to specify the server's ip address and the port number (inside the configuration of socketio.php explained earlier).
If your server is example.com and you configure socketio.php to run on port 400
then you need to connect with $.websocket('ws://example.com:400').
However, you need to start your server before attempting connection with the client.
If you are running on localhost, then your server ip should be something like 127.0.0.1.
phpsocket.io can re-use any existing MySQLi connection. To implement this library in developing your plugins, you need to look at the Advanced Start section and figure out how to get the MySQLi handle of your framework.
Issues and feature requests are very welcome.
Inspired by the general open-source community with special thanks to Github for making the life of programmers more fun.
Check out an awesome developer portal created by yours truly.
Anthony Ogundipe a.k.a. dhtml
Special thanks to Adewale Wilson for his contributions to this library.
phpsocket.io is licensed under the MIT License.