PHP code example of socket-bridge / laravel-socketio

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

    

socket-bridge / laravel-socketio example snippets




namespace App\Listeners;

final class HandleSocketTestEvent
{
    public function handle(array $payload, int|string $userId): array
    {
        return [
            'message' => 'testEvent received',
            'user_id' => $userId,
            'payload' => $payload,
        ];
    }
}

use Burhan\SocketBridge\SocketEventRegistry;

public function boot(SocketEventRegistry $socketEvents): void
{
    $socketEvents->listen('UpdateProgress', function (array $payload, int|string $userId) {
        // Validate the payload and apply your application logic here.
        return [
            'user_id' => $userId,
            'payload' => $payload,
        ];
    });
}

use Burhan\SocketBridge\SocketEventRegistry;

public function boot(SocketEventRegistry $socketEvents): void
{
    $socketEvents->listen('testEvent', function (array $payload, int|string $userId) {
        return [
            'message' => 'testEvent received',
            'user_id' => $userId,
            'payload' => $payload,
        ];
    });
}
bash
php artisan vendor:publish --tag=socket-bridge-config
bash
php artisan socket-bridge:install
bash
php artisan socket-bridge:install --start
bash
php artisan socket-bridge:install
bash
php artisan vendor:publish --tag=socket-bridge-config --force
text
config/socket-bridge.php
bash
# Terminal 1
redis-server

# Terminal 2
php artisan serve

# Terminal 3
php artisan socket-bridge:install --start