PHP code example of emprove / centrifuge-broadcaster

1. Go to this page and download the library: Download emprove/centrifuge-broadcaster 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/ */

    

emprove / centrifuge-broadcaster example snippets


'providers' => [
    // ...
    Emprove\Centrifugo\CentrifugoServiceProvider::class,

    // And uncomment BroadcastServiceProvider
    App\Providers\BroadcastServiceProvider::class,
],

'connections' => [
    'centrifuge' => [
        'driver'       => 'centrifuge',
        'url'          => env('CENTRIFUGE_URL', 'http://127.0.0.1:8000'),
        'token_ttl'    => env('CENTRIFUGE_TOKEN_TTL', 3600),
        'token_issuer' => env('APP_URL', 'default'),
        'secret'       => env('CENTRIFUGE_SECRET', null),
        'api_key'      => env('CENTRIFUGE_API_KEY', null),
        'ssl_key'      => env('CENTRIFUGE_SSL_KEY', null),
        'verify'       => env('CENTRIFUGE_VERIFY', false),
    ],
    // ...
],



namespace App\Http\Controllers;

use Emprove\Centrifugo\Contracts\Centrifugo;

class ExampleController extends Controller
{
    public function home(Centrifugo $centrifuge)
    {
        // Send message into channel
        $centrifuge->publish('channel-name', [
            'key' => 'value'
        ]);

        // Generate api sign
        $apiSign = $centrifuge->generateApiSign('data');

        // ...
    }
}