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 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

多进程模式(Prefork):父进程 bind+listen,子进程继承 fd 并各自 accept

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 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 进程,每个 Worker 独立 bind(REUSEPORT)+listen+accept。 设为 0 或不调用此方法 = 单进程模式(默认行为不变)。

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


Copyright 2022 the Swow contributors