PHP code example of laracomponents / centrifuge-broadcaster

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

    

laracomponents / centrifuge-broadcaster example snippets


'providers' => [
    // ...
    LaraComponents\Centrifuge\CentrifugeServiceProvider::class,

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

'connections' => [
    'centrifuge' => [
        'driver' => 'centrifuge',
        'secret' => env('CENTRIFUGE_SECRET'), // you secret key
        'url' => env('CENTRIFUGE_URL', 'http://localhost:8000'), // centrifuge api url
        'redis_api' => env('CENTRIFUGE_REDIS_API', false), // enable or disable Redis API
        'redis_connection' => env('CENTRIFUGE_REDIS_CONNECTION', 'default'), // name of redis connection
        'redis_prefix' => env('CENTRIFUGE_REDIS_PREFIX', 'centrifugo'), // prefix name for queue in Redis
        'redis_num_shards' => env('CENTRIFUGE_REDIS_NUM_SHARDS', 0), // number of shards for redis API queue
        'verify' => env('CENTRIFUGE_VERIFY', false), // Verify host ssl if centrifuge uses this
        'ssl_key' => env('CENTRIFUGE_SSL_KEY', null), // Self-Signed SSl Key for Host (

'redis' => [
    'centrifuge' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),,
        'password' => env('REDIS_PASSWORD', null),
        'port' =>  env('REDIS_PORT', 6379),
        'database' => 0,
    ],
    // ...
],



namespace App\Http\Controllers;

use LaraComponents\Centrifuge\Centrifuge;

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

        // Generate token
        $token = $centrifuge->generateToken('user id', 'timestamp', 'info');

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

        // ...
    }
}