PHPackages                             alexusmai/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. [API Development](/categories/api)
4. /
5. alexusmai/laravel-centrifugo

ActiveLibrary[API Development](/categories/api)

alexusmai/laravel-centrifugo
============================

Centrifugo broadcaster for laravel 9 and Centrifugo 4

1.7(1mo ago)86.2k↓20%MITPHPPHP ^8.0

Since Dec 8Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (9)Used By (0)

Laravel + Centrifugo 4
======================

[](#laravel--centrifugo-4)

Centrifugo broadcast driver for Laravel
---------------------------------------

[](#centrifugo-broadcast-driver-for-laravel)

Introduction
------------

[](#introduction)

Centrifugo broadcaster for laravel , based on:

- [LaraComponents/centrifugo-broadcaster](https://github.com/LaraComponents/centrifugo-broadcaster)
- [centrifugal/phpcent](https://github.com/centrifugal/phpcent)
- [denis660/laravel-centrifugo](https://github.com/denis660/laravel-centrifugo)

Features
--------

[](#features)

- Compatible with [Centrifugo 4](https://github.com/centrifugal/centrifugo) 🚀
- Wrapper over [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api) 🔌
- Authentication with JWT token (HMAC algorithm) for anonymous, authenticated user and private channel 🗝️

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

[](#requirements)

- PHP &gt;= 8.0
- Laravel 9.0 - 13
- guzzlehttp/guzzle 7
- Centrifugo Server 4

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

[](#installation)

Require this package with composer:

```
composer req alexusmai/laravel-centrifugo
```

Open your config/app.php and add the following to the providers array:

```
'providers' => [
    // And uncomment BroadcastServiceProvider
    App\Providers\BroadcastServiceProvider::class,
],
```

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

```
        'centrifugo' => [
            'driver' => 'centrifugo',
            'token_hmac_secret_key' => env('CENTRIFUGO_TOKEN_HMAC_SECRET_KEY',''),
            'api_key'               => env('CENTRIFUGO_API_KEY',''),
            'url'                   => env('CENTRIFUGO_URL', 'http://localhost:8000'), // centrifugo 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)
            'use_namespace'         => env('CENTRIFUGO_USE_NAMESPACE', false),
            'default_namespace'     => env('CENTRIFUGO_DEFAULT_NAMESPACE', 'default:'),
            'private_namespace'     => env('CENTRIFUGO_PRIVATE_NAMESPACE', 'private:'),
            'presence_namespace'    => env('CENTRIFUGO_PRESENCE_NAMESPACE', 'presence:'),
        ],
```

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

```
CENTRIFUGO_TOKEN_HMAC_SECRET_KEY=token_hmac_secret_key-from-centrifugo-config
CENTRIFUGO_API_KEY=api_key-from-centrifugo-config
CENTRIFUGO_URL=http://localhost:8000

```

These lines are optional:

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

```

[Centrifugo namespaces](https://centrifugal.dev/docs/server/channels)

```
CENTRIFUGO_USE_NAMESPACE=true           // use centrifugo namespaces
CENTRIFUGO_DEFAULT_NAMESPACE=default:   // add to channel name default namespace - default:channel_name
CENTRIFUGO_PRIVATE_NAMESPACE=private:   // change default "private-" laravel prefix to private namespace - private-channel_name -> private:channel_name
CENTRIFUGO_PRESENCE_NAMESPACE=presence: // change default "presence-" laravel prefix to presence namespace - presence-channel_name -> presence:channel_name

```

Don't forget to change `BROADCAST_DRIVER` setting in .env file!

```
BROADCAST_DRIVER=centrifugo

```

Basic Usage
-----------

[](#basic-usage)

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

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

A simple client usage example:

```
