kismia/centrifugo-bundle

A Centrifugo bundle for Symfony

Installs: 22 352

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 3

Forks: 1

Open Issues: 0

Type:symfony-bundle

1.0.2 2019-08-14 12:54 UTC

This package is not auto-updated.

Last update: 2024-05-12 03:14:19 UTC


README

This is wrapper for PHP client for Centrifugo real-time messaging server.

Installation

Install the latest version with

composer require kismia/centrifugo-bundle

Register bundle in app\AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            .......
            new \Kismia\CentrifugoBundle\CentrifugoBundle()
        ];
    }

Configure centrifugo-bundle. In the config file add the following lines

centrifugo:
    apiendpoint: 'http//example.com/api/'
    secret: 'secret api key'
    transport:
        redis:
            host: 'localhost'
            shards: 6
            db: 2
            timeout: 0.3
            port: 6379
        http: []

Basic usage

<?php
    $userId = 1;
    $channel = '#chan_1';
    $messageData = ['message' => 'Hello, world!'];
    
    //instance of Centrifugo client class
    $centrifugo = $this->get('centrifugo.client');
    
    //Send message into channel.
    $response = $centrifugo->publish($channel, $messageData);
            
    //Very similar to publish but allows to send the same data into many channels.
    $response = $centrifugo->broadcast($channels, $messageData);        
            
    //Unsubscribe user from channel.
    $response = $centrifugo->unsubscribe($channel, $userId);
            
    //Disconnect user by user ID.
    $response = $centrifugo->disconnect($userId);
            
    //Get channel presence information (all clients currently subscribed on this channel).
    $response = $centrifugo->presence($channel);
            
    //Get channel history information (list of last messages sent into channel).
    $response = $centrifugo->history($channel);
            
    //Get channels information (list of currently active channels).
    $response = $centrifugo->channels();
            
    //Get stats information about running server nodes.
    $response = $centrifugo->stats();
            
    //Get information about single Centrifugo node.
    $response = $centrifugo->node('http://node1.example.com/api/');