swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 785 forks source link

HTTP控制器中无法调用 websocket 发送消息api #1495

Open aikonchem opened 1 year ago

aikonchem commented 1 year ago
Q A
Bug report? no
Feature request? yes
Swoft version 2.1
Swoole version 5.1
PHP version 8.1
Runtime environment Mac

Describe the bug 在http控制器调用 /* @var \Swoole\WebSocket\Server $server / $server->push(1, 'hello, welcome! :)'); 提示Undefined variable $server bean配置文件 'wsServer' => [ 'class' => WebSocketServer::class, 'port' => 18308, 'listener' => [ //'rpc' => bean('rpcServer'), 'tcp' => bean('tcpServer'), ], 'on' => [ // Enable http handle SwooleEvent::REQUEST => bean(RequestListener::class), // Enable task must add task and finish event SwooleEvent::TASK => bean(TaskListener::class), SwooleEvent::FINISH => bean(FinishListener::class) ], //'debug' => 1, 'debug' => env('SWOFT_DEBUG', 0), / @see WebSocketServer::$setting / 'setting' => [ 'task_worker_num' => 6, 'task_enable_coroutine' => true, 'worker_num' => 6, 'log_file' => alias('@runtime/swoole.log'), // 'open_websocket_close_frame' => true, ],