jiechengyang/swoole-reverb

swoole laravel reverb server

v0.0.2 2025-03-15 13:47 UTC

This package is auto-updated.

Last update: 2025-03-15 13:48:23 UTC


README

SwooleReverb 是一个将 Swoole 与 Laravel Reverb 集成的包,用于高性能的 WebSocket 和 Pub/Sub 消息传递。

安装

使用 Composer 安装该包:

composer require jiechengyang/swoole-reverb

配置

发布:

php artisan vendor:publish --provider="SwooleReverb\Providers\SwooleReverbServerProvider"

根据需要更新配置文件 config/swoole-reverb.php

return [
    'host' => env('REVERB_HOST', env('REVERB_HOST', '0.0.0.0')),
    'port' => env('SWOOLE_REVERB_PORT', env('REVERB_PORT', 8084)),
    'scheme' => env('REVERB_SCHEME', env('REVERB_SCHEME', 'http')),
    'app_id' => env('SWOOLE_REVERB_APP_KEY', env('REVERB_APP_ID')),
    'app_key' => env('SWOOLE_REVERB_APP_KEY', env('REVERB_APP_KEY')),
    'app_secret' => env('SWOOLE_REVERB_APP_SECRET', env('REVERB_APP_SECRET')),
    'connect_clear_tick_time' => env('SWOOLE_CONNECT_CLEAR_TICK_TIME', env('REVERB_APP_PING_INTERVAL', 60)),
    'options' => [
        'worker_num' => 1, //swoole_cpu_num(),
        'daemonize' => false,
        'log_file' => storage_path('logs/swoole_reverb.log'),
        'pid_file' => storage_path('logs/swoole_reverb.pid'),
    ],
    'redis' => [
        // 是否启用Redis通道管理器
        'enabled' => env('SWOOLE_REVERB_REDIS_ENABLED', false),
        // Redis连接配置
        'connection' => env('SWOOLE_REVERB_REDIS_CONNECTION', 'default'),
    ],
];

重点说明:worker_num 如果 > 1,一定开启SWOOLE_REVERB_REDIS_ENABLED。这样才能启动多进程服务,否则worker_num> 1,仍然会以单进程服务启动

启动服务器

使用 Artisan 命令启动 Swoole 服务器:

Description:
  Swoole Reverb Server manager

Usage:
  swoole:reverb [options] [--] <action> [<host> [<port>]]

Arguments:
  action                
  host                  
  port                  

Options:
  -d, --daemon          
      --g               是否优雅的关闭服务
      --debug           是否应在终端中显示调试消息
  -h, --help            Display help for the given command. When no command is given display help for the list command
      --silent          Do not output any message
  -q, --quiet           Only errors are displayed. All other output is suppressed
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  {action}参数可以是以下之一:
  - start: Start the server
  - stop: Stop the server
  - restart: Restart the server
  - status: Get the server status

许可证

该包是开源软件,遵循 MIT 许可证

贡献

欢迎贡献!请提交拉取请求或打开问题讨论你的想法。

致谢

支持

如果你有任何问题或需要支持,请在 GitHub 上打开问题。