Closed joker-hong closed 4 months ago
public static function decode(string $buffer, TcpConnection $connection): Request { static $requests = []; $cacheable = static::$enableCache && !isset($buffer[512]); if (true === $cacheable && isset($requests[$buffer])) { $request = clone $requests[$buffer]; $request->connection = $connection; $connection->request = $request; $request->properties = []; return $request; } $request = new static::$requestClass($buffer); $request->connection = $connection; $connection->request = $request; if (true === $cacheable) { $requests[$buffer] = $request; if (count($requests) > 512) { unset($requests[key($requests)]); } } return $request; }
workerman中http的$request已经是单独实例化了$request = new static::$requestClass($buffer);,属于局部变量了,为啥webman中还需要把请求弄个上下文呢?Context::set(Request::class, $request);
$request = new static::$requestClass($buffer);
Context::set(Request::class, $request);
这里是局部变量,但是这个对象到了外部,webman框架会存储它,以便业务调用request()函数时返回正确的request对象
明白了,谢谢大哥,还有个问题,webman的插件都是围绕着Event/Select来开发的,但Revolt/Swoole/Swow这三种事件又需要连接池,那这样是不是现有的插件不支持切换到这三种事件呢?
workerman中http的$request已经是单独实例化了
$request = new static::$requestClass($buffer);
,属于局部变量了,为啥webman中还需要把请求弄个上下文呢?Context::set(Request::class, $request);