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

1. Go to this page and download the library: Download shakahl/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/ */

    

shakahl / socket.io-php-emitter example snippets


use Predis;
use Shakahl\SocketIO;
...

$client = new Predis\Client();

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

use Predis;
use Shakahl\SocketIO;
...

$client = new Predis\Client();

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

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

use Predis;
use Shakahl\SocketIO;
...

$client = new Predis\Client();

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

use Predis;
use Shakahl\SocketIO;
...

$client = new Predis\Client();

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