Laravel 11 发布了,一并推出了第一方可扩展的 WebSocket 服务器:Laravel Reverb,为你的应用提供强大的实时功能。
Reverb 只支持Laravel 10和Laravel 11,下面以Laravel 11为例
php artisan install:broadcasting
env 配置
REVERB_APP_ID=991168
REVERB_APP_KEY=cwnysrqcajxago4kbhw3
REVERB_APP_SECRET=q8kagq5unvvneork62yl
REVERB_HOST="laravel.cw.net"
REVERB_PORT=9502
REVERB_SCHEME=http
php artisan reverb:start
//或
php artisan reverb:start --port=9502
//或
php artisan reverb:start --debug
//创建广播事件
root@php-fpm:/var/www/example-app# php artisan make:event MessageCreated
//运行reverb
root@php-fpm:/var/www/example-app# php artisan reverb:start --port=9502
//监听队列
root@php-fpm:/var/www/example-app# php artisan queue:listen
//触发事件
root@php-fpm:/var/www/example-app# php artisan tinker
Psy Shell v0.12.2 (PHP 8.2.17 — cli) by Justin Hileman
> event (new \App\Events\MessageCreated('test'))
= []
//网页查看效果
更多请查看: https://cloud.tencent.com/developer/article/2245377