我正在使用workerman的redis,然后报错了,我看到论坛上https://www.workerman.net/q/8084 这个贴子的回复:
我有个疑问,就是怎么同时调用
TcpConnection $connection, Request $request
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/function.php';
// 创建websocket
$worker = new Worker('websocket://0.0.0.0:3000');
$worker->onMessage = function(TcpConnection $connection, Request $request,$data){
......
}
TypeError: {closure}(): Argument #2 ($request) must be of type Workerman\Protocols\Http\Request, string given, called in E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Connection\TcpConnection.php on line 646 and defined in E:\desktop\project\sharkcms\bot\FishBot\start.php:13
Stack trace:
#0 E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Connection\TcpConnection.php(646): {closure}()
#1 E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead()
#2 E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Worker.php(1485): Workerman\Events\Select->loop()
#3 E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Worker.php(1402): Workerman\Worker::forkWorkersForWindows()
#4 E:\desktop\project\sharkcms\bot\FishBot\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()
#5 E:\desktop\project\sharkcms\bot\FishBot\start.php(266): Workerman\Worker::runAll()
#6 {main}
windows workerman v4.1.13
1、websocket是长连接,用不到session。数据可以直接存$connection里,$connection->data = xx;
2、websocket只有握手的时候有一次http请求,其他都是发的数据。onMessage里自然就没有$request
好的,谢谢大佬解答