PHP code example of hannesvdvreken / socketio

1. Go to this page and download the library: Download hannesvdvreken/socketio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hannesvdvreken / socketio example snippets


$io = new Socketio\Socketio;

$chats = $io->of('/chats');

$io->emit('general', $message);
$chats->emit('user.connected', $user);

$io->of('/chats', function ($chats) {
    $chats->emit('user.connected', $user);
});

$io->emit('general', $message);

$io->to('room-a')->emit('event', $message);
$io->to('room-a')->to('room-b')->emit('event', $message);
$io->in('room-c')->emit('event', $message);

$predis = new Predis\Client;
$msgpack = new Socketio\Utils\Msgpack;

$adapter = new Socketio\Adapters\Redis($predis, $msgpack);
$io->adapter($adapter);

$msgpack = new Socketio\Utils\Msgpack(new Msgpack\Encoder, new Msgpack\Decoder);