PHP code example of layman / laravel-websocket

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

    

layman / laravel-websocket example snippets



// 测试
Illuminate\Support\Facades\Route::get('/websocket', function () {
    return view('websocket');
});

// 消息订阅
$client = new \Predis\Client();
$client->publish('redis_subscribe_channel', json_encode([
    'group_id' => null,
    'type' => 'broadcast',
    'from' => 'system',
    'to' => ['xxx', 'xxxx'],
    'content' => 'broadcast',
    'extra' => null,
]));

// auth认证
class Auth implements WebSocketAuthInterface
{
    
}
bash
php artisan vendor:publish --provider="Layman\LaravelWebsocket\WebSocketServiceProvider" --tag=websocket
php artisan vendor:publish --tag=websocket-view
bash
php artisan websocket:start