PHP code example of batformat / phpcent-broadcaster

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

    

batformat / phpcent-broadcaster example snippets


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

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

'connections' => [
    'centrifuge' => [
        'driver'           => 'centrifuge',
        'api_key'          => env('CENTRIFUGE_API_KEY'), // you api key
        '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 TheArdent\Centrifuge\Centrifuge;

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

        // Generate token without expire:
        $token = $centrifuge->generateToken('user id');

        // Connection token that will be valid for 5 minutes:
        $token = $centrifuge->generateConnectionToken('user id', time() + 5*60);

        //It's also possible to generate private channel subscription token:
        $token = $centrifuge->generatePrivateChannelToken('user id', 'channel');
    }
}