Skip to content

Commit

Permalink
5.0.0-rc.4
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Dec 6, 2024
1 parent e25dd32 commit ed4b431
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 4 additions & 1 deletion src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit ed4b431

Please sign in to comment.