Argument #2 ($request) must be of type

fisha

问题描述

我正在使用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}

截图报错信息里报错文件相关代码

截图

操作系统及workerman/webman等框架组件具体版本

windows workerman v4.1.13

769 1 0
1个回答

latin

1、websocket是长连接,用不到session。数据可以直接存$connection里,$connection->data = xx;
2、websocket只有握手的时候有一次http请求,其他都是发的数据。onMessage里自然就没有$request

  • fisha 2023-08-29

    好的,谢谢大佬解答

年代过于久远,无法发表回答
×
🔝