PHP replacement for

What is it?

PHPSocket.IO is a library written in PHP/JavaScript that allows real-time communication between a client and server via web sockets.

In other words, it is very similar to NODE's Easy to use, but powerful and customizable. An essential addition to your development toolbox.

Installation and config


PHP 5.3+

Quick start

You need to start the server from the commandline and not from inside the browser.

$: php server/server.php 
From linux, you may want to use: nohup php server/server.php
The server is meant to be running continuously so that it waits for connection, if you close the server, then the functionality will stop.
After you have successfully started the server, you can run the client from the browser examples/basic/index.html or examples/advanced/index.html


Before running the php server, you need to configure the port to run the socket installation on inside socketio.php


Simple usage

1. The basic example server code (inside socketio.php)

$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.

2. The basic example script

var socket=$.websocket('ws://');
$('form').submit(function() {
  socket.emit('chat message', $('#m').val());
  return false;
socket.on('chat message', function(msg){
socket.on('connect', function(user){
    $('#messages').append($('<li>').text("Welcome "+user));

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 and you configure socketio.php to run on port 400 then you need to connect with $.websocket('ws://'). 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

Online Examples

These examples utilize a multiple chatrooms where everyone can chat simultaenously. You can run any of these chats via different browser tabs, or different browsers or different devices.
No database storage is utilized in any forms in these examples. No session variables were used either.
  1. Click here to run the basic example.
  2. Click here to run the advanced example.
  3. Click here to run the chat im example.

Android Integration

For android users, please check out the links below:
  1. Android Chat Demo (apk download)
  2. Android Chat Sample (source code)
  3. Android Module (source Code)

Notes 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.

License is licensed under the MIT License.