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)

Defer the onOpen callback after handshake completes.

void
reportCallbackFailure(Throwable $throwable)

Report a WebSocket callback failure without escaping the native boundary.

Details

at line 54
__construct(Container $container)

No description

Parameters

Container $container

at line 73
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 95
void onHandshake(Request $request, Response $response)

Handle the WebSocket handshake request.

Converts the Swoole request to HttpFoundation, validates the WebSocket security key, 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 178
void onMessage(Server $server, Frame $frame)

Handle a WebSocket message.

Parameters

Server $server
Frame $frame

Return Value

void

at line 236
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 294
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 304
Server getServer()

Get the Swoole server instance.

Return Value

Server

at line 313
Sender getSender()

Get the WebSocket sender instance.

Return Value

Sender

at line 324
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 332
string getServerName()

Get the server name.

Return Value

string

at line 346
Server setServerName(string $serverName)

Set the server name.

Boot-only. 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 356
protected int getFd(Response $response)

Get the file descriptor from the response.

Parameters

Response $response

Return Value

int

at line 364
protected void deferOnOpen(Request $request, object $instance, Server $server, int $fd)

Defer the onOpen callback after handshake completes.

Parameters

Request $request
object $instance
Server $server
int $fd

Return Value

void

at line 392
protected void reportCallbackFailure(Throwable $throwable)

Report a WebSocket callback failure without escaping the native boundary.

Parameters

Throwable $throwable

Return Value

void