PHP code example of naturalweb / laravel-socketcluster

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

    

naturalweb / laravel-socketcluster example snippets


'providers' => [
    ...
    LaravelSocketCluster\SCBroadcastServiceProvider::class,
    ...
]

'default' => 'socketcluster',

'connections' => [
    ...
    'socketcluster' => [
      'driver' => 'socketcluster',
      'secure' => env('BROADCAST_SOCKETCLUSTER_SECURE', false),
      'host'   => env('BROADCAST_SOCKETCLUSTER_HOST', '127.0.0.1'),
      'port'   => env('BROADCAST_SOCKETCLUSTER_PORT', '3000'),
      'path'   => env('BROADCAST_SOCKETCLUSTER_PATH', '/socketcluster/'),
    ],
    ...
]

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PublishToSocketClusterEvent implements ShouldBroadcast
{
    use SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return ['<channel>'];
    }
}

event(new App\Events\PublishToSocketClusterEvent('Test publish!!'));