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('order_subscribe', Layman\LaravelWebsocket\Cores\Utils::pack(
    1,
    Str::uuid(),
    1,
    1,
    [
        'sender' => 'server',
        'receiver' => 'x123',
        'group_code' => null,
        'notice_type' => 1,
        'files' => [],
    ],
    json_encode([
        'order_code' => 'xxx123',
        'message' => '您有新的订单!',
    ])
));

// auth认证
class Authenticate implements Layman\LaravelWebsocket\Interfaces\AuthenticateInterface
{
    
}
bash
php artisan vendor:publish --provider="Layman\LaravelWebsocket\WebsocketServiceProvider" --tag=websocket-config
php artisan vendor:publish --tag=websocket-views
bash
php artisan websocket:start