This is automatic generated document for things in Swow\Psr7\Server\EventDriver class

Class EventDriver

Properties

protected $closeHandler protected $connectionHandler protected $exceptionHandler protected $messageHandler protected $requestHandler protected $server protected $startHandler protected $upgradeHandler protected $workerCount

Methods

Method __construct

public function __construct ( ?Server $server )

Method resolveReusePortListenPort

protected function resolveReusePortListenPort ( string $name , int $port ) : int

Method runAcceptLoop

protected function runAcceptLoop ( Server $server ) : void

Accept 循环:单进程和多进程复用同一逻辑

Method solveUpgradeResponse

protected function solveUpgradeResponse ( mixed $upgradeResponse ) : ResponseInterface

Method startMultiProcess

protected function startMultiProcess ( string $name , int $port ) : void

多进程模式:支持 TCP REUSEPORT 负载均衡时每个 Worker 独立监听,否则保留 prefork 共享 fd。

Method startOn

public function startOn ( string $name , int $port ) : void

Method startSingleProcess

protected function startSingleProcess ( string $name , int $port ) : void

单进程模式

Method stop

public function stop ( ) : void

Method supportsTcpReusePortLoadBalancing

protected function supportsTcpReusePortLoadBalancing ( ) : bool

由 Swow 扩展报告当前构建是否支持 TCP REUSEPORT 负载均衡语义。

Method withCloseHandler

public function withCloseHandler ( callable(ServerConnection): void $handler ) : static

Method withConnectionHandler

public function withConnectionHandler ( callable(ServerConnection): void $handler ) : static

Method withExceptionHandler

public function withExceptionHandler ( callable(ServerConnection, Exception): void $handler ) : static

Method withMessageHandler

public function withMessageHandler ( callable(ServerConnection, WebSocketFrameInterface): mixed $handler ) : static

Method withRequestHandler

public function withRequestHandler ( callable(ServerConnection, ServerRequestPlusInterface): mixed $handler ) : static

Method withStartHandler

public function withStartHandler ( callable(Server): void $handler ) : static

Method withWorkerCount

public function withWorkerCount ( int $count ) : static

设置多进程 Worker 数量

启用后 startOn() 会自动 fork 多个 Worker 进程,并按当前平台能力选择独立 REUSEPORT 监听或共享 fd。 设为 0 或不调用此方法 = 单进程模式(默认行为不变)。

Param int $count Worker 数量,0 = 单进程


Copyright 2022 the Swow contributors