PHP code example of valeriitropin / socketio-redis-adapter

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

    

valeriitropin / socketio-redis-adapter example snippets


use React\EventLoop\Factory as ReactFactory;
use ValeriiTropin\Socketio\RedisAdapter;
use Clue\React\Block;
use React\Promise;

$loop = ReactFactory::create();
$client = new RedisAdapter($loop);

$promise = $client->allRooms()->then(function ($rooms) use ($client) {
    $promises = [];
    foreach ($rooms as $room) {
        $promises[] = $client->clients([$room])->then(function ($clients) use ($room) {
            foreach ($clients as $client) {
                echo $room . ' ' . $client . "\n";
            }
        });
    }
    return Promise\all($promises);
})->otherwise(function ($error) {
    echo ($error->getMessage()) . "\n";
});

Block\await($promise, $loop);

$adapter->clients($rooms)
    ->then(function ($clients) {
        var_dump($clients);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->clients($id)
    ->then(function ($rooms) {
        var_dump($rooms);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->allRooms()
    ->then(function ($allRooms) {
        var_dump($allRooms);
    })
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->remoteJoin($id, $room)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->remoteLeave($id, $room)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->remoteDisconnect($id, $close)
    ->then(function () {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });

$adapter->customRequest($data)
    ->then(function ($replies) {})
    ->otherwise(function ($error) {
        echo ($error->getMessage()) . "\n";
    });