node

for perl there is no socket.io library, for php there are a few including the php-emitter.
For me nothing worked really well, so i decided to communicate with my socket.io server the unix way.
in production i use php -> node socket.io client -> node socket.io server
where php and the socket.io client running on the same server.
it run's very well and serves over 500.000 users monthly.

here is my node.js script to open a unix socket.
Every line the socket gets will be emitted

var net = require('net');  
var fs = require('fs');

//do the connect
var io = require('socket.io-client').connect(  
        'http://other_server', {
        port: 80
});

if (fs.existsSync('/tmp/node_socket')) {  
    fs.unlinkSync('/tmp/node_socket');
}

var server = net.createServer(function(con) {  
    con.on('data', function(data) {
        if(typeof data != 'undefined' && data != null)
        {
            var str = data.toString();
            var arr = str.split("\n");
            arr.forEach(function(string) {
                 if ( string ) {
                     console.log('Data received by socket: ' + string);
                     io.emit('something', JSON.parse(string));
                 }
            })

        }
    });

});

server.listen('/tmp/node_socket');  

in php i simply do

$sock = stream_socket_client('unix:///tmp/node_socket', $errno, $errstr);
fwrite($sock, 'SOME string'."\n");  

install nodejs as you would normaly do, apt-get, extra repo or compile it by yourself

after that create a new user and set the Homedirectory (here /node).
all my nodeapplications are located under /node
i think something like /var/www/node would be cleaner

useradd -s /bin/bash -m -d /node -c "node.js" node  

now this user needs the right to open port 80 or any other privileged port you want. there are several ways, mine is to install libcap2 and give the application the right

apt-get install libcap2-bin  

give the node binary the right:

setcap cap_net_bind_service=+ep /usr/bin/nodejs  

install pm2, a node application to manage node applications ;-)

npm install pm2 -g --unsafe-perm  

set it up to startup on boot and run the applications as user node

pm2 startup -u node ubuntu  

now switch to user node an start your application and save these states for reboots

su - node  
NODE_ENV=production pm2 start blog.js  
pm2 save  

thats it, play a little with pm2, its really nice, try some of these:

pm2 status  
pm2 monit  
pm2 logs  
pm2 restart blog  
pm2 delete blog