From ed4b431938cd1e0a6a21ea5cca1efba9795004db Mon Sep 17 00:00:00 2001 From: walkor Date: Fri, 6 Dec 2024 15:54:46 +0800 Subject: [PATCH] 5.0.0-rc.4 --- src/Connection/TcpConnection.php | 23 ++++++++++++++++++++++- src/Worker.php | 5 ++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index 9f33f093..b9cbbc2d 100644 --- a/src/Connection/TcpConnection.php +++ b/src/Connection/TcpConnection.php @@ -19,7 +19,10 @@ use RuntimeException; use stdClass; use Throwable; +use Workerman\Events\Ev; +use Workerman\Events\Event; use Workerman\Events\EventInterface; +use Workerman\Events\Select; use Workerman\Protocols\Http\Request; use Workerman\Protocols\ProtocolInterface; use Workerman\Worker; @@ -349,6 +352,14 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable */ public static array $connections = []; + + /** + * Reuse request. + * + * @var bool + */ + protected static bool $reuseRequest = false; + /** * Status to string. * @@ -675,7 +686,7 @@ public function baseRead($socket, bool $checkEof = true): void $this->error($e); } $request->destroy(); - $requests[$buffer] = clone $request; + $requests[$buffer] = static::$reuseRequest ? $request : clone $request; return; } try { @@ -1087,6 +1098,16 @@ public static function enableCache(bool $value = true): void static::$enableCache = $value; } + /** + * Init. + * + * @return void + */ + public static function init(): void + { + static::$reuseRequest = in_array(get_class(Worker::$globalEvent), [Event::class, Select::class, Ev::class]); + } + /** * Get the json_encode information. * diff --git a/src/Worker.php b/src/Worker.php index 2f4f5849..3e25d690 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -59,7 +59,7 @@ class Worker * * @var string */ - final public const VERSION = '5.0.0-rc.3'; + final public const VERSION = '5.0.0-rc.4'; /** * Status starting. @@ -1709,6 +1709,9 @@ protected static function forkOneWorkerForLinux(self $worker): void // Init Timer. Timer::init(static::$globalEvent); + // Init TcpConnection. + TcpConnection::init(); + restore_error_handler(); static::setProcessTitle('WorkerMan: worker process ' . $worker->name . ' ' . $worker->getSocketName());