class Server implements BootstrapsForServer, OnHandshakeInterface, OnCloseInterface, OnMessageInterface

Properties

protected HandshakeHandler $handshakeHandler
protected Dispatcher|null $event
protected StdoutLoggerInterface $logger
protected string $serverName

Methods

__construct(Container $container)

No description

void
bootstrapForServer(string $serverName)

Bootstrap the application and initialize WebSocket components.

void
onHandshake(Request $request, Response $response)

Handle the WebSocket handshake request.

void
onMessage(Server $server, Frame $frame)

Handle a WebSocket message.

void
onClose(Server $server, int $fd, int $reactorId)

Handle a WebSocket connection close.

Response
handleException(Throwable $throwable)

Handle an exception that occurred during the handshake.

Server
getServer()

Get the Swoole server instance.

getSender()

Get the WebSocket sender instance.

getRouter()

Get the router instance for WebSocket handshake route matching.

string
getServerName()

Get the server name.

setServerName(string $serverName)

Set the server name.

int
getFd(Response $response)

Get the file descriptor from the response.

void
deferOnOpen(Request $request, object $instance, Server $server, int $fd, Request $httpRequest, Response $httpResponse)

Defer connection opening and cleanup until the handshake coroutine exits.

requestCanceled(Request $request, Response|null $response, Throwable|null $exception, Throwable $cancellation)

Notify listeners that cancellation stopped a handshake request's lifecycle.

void
reportCallbackFailure(Throwable $throwable)

Report a WebSocket callback failure without escaping the native boundary.

Details

at line 67
__construct(Container $container)

No description

Parameters

Container $container

at line 86
void bootstrapForServer(string $serverName)

Bootstrap the application and initialize WebSocket components.

Called by the server boot process (Server\Server::registerSwooleEvents) before $server->start(). Resolves the HTTP Kernel to ensure the application is bootstrapped (routes compiled, middleware synced) even in WS-only setups where HttpServer\Server may not be present. The hasBeenBootstrapped() guard makes this idempotent.

Parameters

string $serverName

Return Value

void

at line 109
void onHandshake(Request $request, Response $response)

Handle the WebSocket handshake request.

Converts the Swoole request to HttpFoundation, validates the WebSocket security key and version, dispatches through the Router for route matching and middleware execution, then builds the 101 Switching Protocols response.

Parameters

Request $request
Response $response

Return Value

void

at line 302
void onMessage(Server $server, Frame $frame)

Handle a WebSocket message.

Parameters

Server $server
Frame $frame

Return Value

void

at line 389
void onClose(Server $server, int $fd, int $reactorId)

Handle a WebSocket connection close.

Parameters

Server $server
int $fd
int $reactorId

Return Value

void

at line 485
protected Response handleException(Throwable $throwable)

Handle an exception that occurred during the handshake.

Subclasses (e.g. Foundation\Http\WebSocketKernel) override this to use the application's exception handler instead of the default.

Parameters

Throwable $throwable

Return Value

Response

at line 504
Server getServer()

Get the Swoole server instance.

Return Value

Server

at line 513
Sender getSender()

Get the WebSocket sender instance.

Return Value

Sender

at line 524
protected Router getRouter()

Get the router instance for WebSocket handshake route matching.

Override in subclasses to use an isolated router for packages that register their own server entry (e.g. Reverb).

Return Value

Router

at line 532
string getServerName()

Get the server name.

Return Value

string

at line 546
Server setServerName(string $serverName)

Set the server name.

Mutates the worker-lifetime WebSocket handler before Swoole starts; runtime use races across connections and changes emitted server context.

Parameters

string $serverName

Return Value

Server

at line 557
protected int getFd(Response $response)

Get the file descriptor from the response.

Parameters

Response $response

Return Value

int

at line 565
protected void deferOnOpen(Request $request, object $instance, Server $server, int $fd, Request $httpRequest, Response $httpResponse)

Defer connection opening and cleanup until the handshake coroutine exits.

Parameters

Request $request
object $instance
Server $server
int $fd
Request $httpRequest
Response $httpResponse

Return Value

void

at line 717
protected Throwable requestCanceled(Request $request, Response|null $response, Throwable|null $exception, Throwable $cancellation)

Notify listeners that cancellation stopped a handshake request's lifecycle.

Returns the throwable to propagate, so a listener failure never replaces the cancellation.

Parameters

Request $request
Response|null $response
Throwable|null $exception
Throwable $cancellation

Return Value

Throwable

at line 764
protected void reportCallbackFailure(Throwable $throwable)

Report a WebSocket callback failure without escaping the native boundary.

A direct cancellation is control flow and is not reported; a cleanup failure carrying it is.

Parameters

Throwable $throwable

Return Value

void