PHP code example of ruslanmelnychenko / socket.io-php-emitter

1. Go to this page and download the library: Download ruslanmelnychenko/socket.io-php-emitter 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/ */

    

ruslanmelnychenko / socket.io-php-emitter example snippets


use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();

(new Emitter($client))
    ->of('namespace')->emit('event', 'payload message');

use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();
$client->connect('127.0.0.1');

(new Emitter($client))
    ->broadcast->emit('broadcast-event', 'payload message');

(new Emitter($client))
    ->flag('broadcast')->emit('broadcast-event', 'payload message');

use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();
$client->connect('127.0.0.1');

(new Emitter($client))
    ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);

use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();
$client->connect('127.0.0.1');

(new Emitter($client))
    ->in(['room1', 'room2'])
    ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);

use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();
$client->connect('127.0.0.1');

(new Emitter($client))
    ->in(['room1', 'room2'])
    ->except(['room3'])
    ->emit('broadcast-event', ['param1' => 'value1', 'param2' => 'value2', ]);

use RuslanMelnychenko\SocketIO\Emitter;
...

$client = new \Redis();
$client->connect('127.0.0.1');

(new Emitter($client))
    ->in(['room1', 'room2'])
    ->except(['room3'])
    ->socketsJoin('room4');
    
(new Emitter($client))
    ->in(['room4'])
    ->socketsLeave('room3');
    
(new Emitter($client))
    ->in(['room1'])
    ->disconnectSockets();

(new Emitter($client))
    ->of('/tasks')
    ->serverSideEmit('taskDone', 1);