PHPackages                             meetjet/laravel-centrifugo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. meetjet/laravel-centrifugo

ActiveLibrary

meetjet/laravel-centrifugo
==========================

This is my package laravel-centrifugo

1.0.1(4y ago)8341MITPHPPHP ^7.3|^8.0

Since Oct 15Pushed 4y agoCompare

[ Source](https://github.com/meetjet/laravel-centrifugo)[ Packagist](https://packagist.org/packages/meetjet/laravel-centrifugo)[ Docs](https://github.com/meetjet/laravel-centrifugo)[ GitHub Sponsors](https://github.com/meetjet)[ RSS](/packages/meetjet-laravel-centrifugo/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (10)Versions (3)Used By (0)

Laravel Centrifugo
==================

[](#laravel-centrifugo)

[![Latest Version on Packagist](https://camo.githubusercontent.com/06652f0382ff182efeaf1e88901d2fa244d3ff82627ee7fcc4c780493cf8dd7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6565746a65742f6c61726176656c2d63656e7472696675676f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/meetjet/laravel-centrifugo)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9e15d3c1454f0c9b5ccffccc1e6c9285d462f41883c8ba4034834921bcf791f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6565746a65742f6c61726176656c2d63656e7472696675676f2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/meetjet/laravel-centrifugo/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1d7672b52b9a9bb19882bc18baec898c0d14a8c31da7497ac1b65384268924a0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6565746a65742f6c61726176656c2d63656e7472696675676f2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/meetjet/laravel-centrifugo/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ee9793d3865e841f810b74ed3e7bab67d5b719a4959a80ada60d0d9844e70f1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6565746a65742f6c61726176656c2d63656e7472696675676f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/meetjet/laravel-centrifugo)

Features
--------

[](#features)

- Compatible with latest [Centrifugo 3.0.3](https://github.com/centrifugal/centrifugo/releases/tag/v3.0.3)
- Contains instructions and configuration file for setting up with Laravel Sail

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Laravel 7.30.4 - 8
- Guzzle 6 - 7
- Centrifugo Server 3.0.3 or newer (see [here](https://github.com/centrifugal/centrifugo))

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require meetjet/laravel-centrifugo
```

Open your config/broadcasting.php and add new connection like this:

```
'centrifugo' => [
    'driver' => 'centrifugo',
    'secret'  => env('CENTRIFUGO_SECRET'),
    'apikey'  => env('CENTRIFUGO_APIKEY'),
    'url'     => env('CENTRIFUGO_URL', 'http://localhost:8000'), // Centrifugo server api url
    'verify'  => env('CENTRIFUGO_VERIFY', false), // Verify host ssl if centrifugo uses this
    'ssl_key' => env('CENTRIFUGO_SSL_KEY', null), // Self-Signed SSl Key for Host (require verify=true)
],
```

Also, you should add these two lines to your .env file:

```
CENTRIFUGO_SECRET=token_hmac_secret_key-from-centrifugo-config
CENTRIFUGO_APIKEY=api_key-from-centrifugo-config
CENTRIFUGO_URL=http://localhost:8000

```

These lines are optional:

```
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=false

```

Then change `BROADCAST_DRIVER` setting in .env file:

```
BROADCAST_DRIVER=centrifugo

```

You can publish the config file with:

```
php artisan vendor:publish --provider="Meetjet\LaravelCentrifugo\LaravelCentrifugoServiceProvider" --tag="laravel-centrifugo-config"
```

This is the contents of the published config file:

```
return [
];
```

Setup local Centrifugo server with Laravel Sail
-----------------------------------------------

[](#setup-local-centrifugo-server-with-laravel-sail)

Copy centrifugo config file to project root folder via command:

```
php artisan centrifugo:setup
```

Add Centrifugo config block into services section of docker-compose.yml file:

```
centrifugo:
    image: centrifugo/centrifugo:latest
    volumes:
        - ./centrifugo.json:/centrifugo/centrifugo.json
    command: centrifugo -c centrifugo.json
    ports:
        - '8008:8008'
    networks:
        - sail
    ulimits:
        nofile:
            soft: 65535
            hard: 65535

```

Open your .env and change centrifugo api url:

```
CENTRIFUGO_URL=http://centrifugo:8008

```

Restart Laravel Sail.

Usage
-----

[](#usage)

To configure Centrifugo server, read [official documentation](https://centrifugal.github.io/centrifugo/)

For broadcasting events, see [official documentation of Laravel](https://laravel.com/docs/8.x/broadcasting)

### Usage with Centrifugo Client

[](#usage-with-centrifugo-client)

```
$centrifugo = new Meetjet\LaravelCentrifugo();

// Send message into channel
$centrifugo->publish('public', ['message' => 'Hello world']);

// Generate connection token
$token = $centrifugo->generateConnectionToken((string)Auth::id(), 0, [
    'name' => Auth::user()->name,
]);

// Generate private channel token
$apiSign = $centrifugo->generatePrivateChannelToken((string)Auth::id(), 'channel', time() + 5 * 60, [
    'name' => Auth::user()->name,
]);

//Get a list of currently active channels.
$centrifugo->channels();

//Get channel presence information (all clients currently subscribed on this channel).
$centrifugo->presence('public');
```

### Usage with Laravel Broadcast feature

[](#usage-with-laravel-broadcast-feature)

```
