WebSocketKernel
class WebSocketKernel extends Server
Properties
| protected HandshakeHandler | $handshakeHandler | from Server | |
| protected Dispatcher|null | $event | from Server | |
| protected StdoutLoggerInterface | $logger | from Server | |
| protected string | $serverName | from Server |
Methods
Bootstrap the application and initialize WebSocket components.
Handle the WebSocket handshake request.
Handle a WebSocket connection close.
Handle an exception using the application's exception handler.
Defer the onOpen callback after handshake completes.
Report a WebSocket callback failure without escaping the native boundary.
Details
in
Server 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.
in
Server 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.
in
Server at line 178
void
onMessage(Server $server, Frame $frame)
Handle a WebSocket message.
in
Server at line 236
void
onClose(Server $server, int $fd, int $reactorId)
Handle a WebSocket connection close.
at line 21
protected Response
handleException(Throwable $throwable)
Handle an exception using the application's exception handler.
Overrides the base WebSocket handler to use the app-level exception handler, matching how the HTTP kernel delegates exception handling.
in
Server at line 304
Server
getServer()
Get the Swoole server instance.
in
Server 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).
in
Server at line 332
string
getServerName()
Get the server name.
in
Server 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.
in
Server at line 356
protected int
getFd(Response $response)
Get the file descriptor from the response.
in
Server at line 364
protected void
deferOnOpen(Request $request, object $instance, Server $server, int $fd)
Defer the onOpen callback after handshake completes.