PHP code example of mkiselev / yii2-broadcasting

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

    

mkiselev / yii2-broadcasting example snippets


'bootstrap' => ['broadcasting'],
'modules' => [
    'broadcasting' => [
        'class' => \mkiselev\broadcasting\Module::class,
        'broadcaster' => [
            'class' => \mkiselev\broadcasting\broadcasters\RedisBroadcaster::class,
            // By default will be used redis application component, but you can configure as you want
            'redis' => [
                'class' => \yii\redis\Connection::class,
            ],
            // Configure auth callback for private and presitance chanells
            'channels' => [
                'signal' => function (\yii\web\User $user) {
                    return $user->can('something');
                },
            ],
        ],
    ],
],



namespace common\models;

use mkiselev\broadcasting\channels\PrivateChannel;
use mkiselev\broadcasting\events\BroadcastEvent;

class SignalEvent extends BroadcastEvent
{
    public $someParam = 42;

    public function broadcastOn()
    {
        return new PrivateChannel('signal');
    }

    public function broadcastAs()
    {
        return 'new';
    }
}

(new common\models\SignalEvent(['someParam' => 146]))->toOthers()->broadcast();