SwooleConnectionContext
in package
implements
WebSocketContext
Tags
Table of Contents
Interfaces
- WebSocketContext
- Runtime context for an active WebSocket connection.
Methods
- __construct() : mixed
- close() : void
- Close the WebSocket connection with an optional status code and reason.
- id() : int
- Returns the numeric connection identifier assigned by the server.
- isAlive() : bool
- Returns true if the connection is still open and accepting frames.
- request() : ServerRequestInterface
- Returns the original HTTP upgrade request that initiated the connection.
- send() : void
- Send a UTF-8 text frame to the client.
- sendBinary() : void
- Send a binary frame to the client.
- sendPing() : void
- Send a WebSocket ping frame to check connection liveness.
- withRequest() : WebSocketContext
- Return a copy of the context with a different underlying PSR-7 request.
Methods
__construct()
public
__construct(Server $server, int $fd, ServerRequestInterface $request) : mixed
Parameters
- $server : Server
- $fd : int
- $request : ServerRequestInterface
close()
Close the WebSocket connection with an optional status code and reason.
public
close([int $code = 1000 ][, string $reason = '' ]) : void
Parameters
- $code : int = 1000
-
WebSocket close code (default 1000 = normal closure).
- $reason : string = ''
-
Human-readable reason phrase sent to the client.
id()
Returns the numeric connection identifier assigned by the server.
public
id() : int
Return values
intisAlive()
Returns true if the connection is still open and accepting frames.
public
isAlive() : bool
Tags
Return values
boolrequest()
Returns the original HTTP upgrade request that initiated the connection.
public
request() : ServerRequestInterface
Useful for reading headers, cookies, or query parameters set during the WebSocket handshake (e.g. authentication tokens or channel parameters).
Return values
ServerRequestInterfacesend()
Send a UTF-8 text frame to the client.
public
send(string $text) : void
Parameters
- $text : string
-
The UTF-8 encoded payload to transmit.
sendBinary()
Send a binary frame to the client.
public
sendBinary(string $data) : void
Parameters
- $data : string
-
The raw binary payload to transmit.
sendPing()
Send a WebSocket ping frame to check connection liveness.
public
sendPing() : void
The client should respond with a pong frame automatically.
withRequest()
Return a copy of the context with a different underlying PSR-7 request.
public
withRequest(ServerRequestInterface $request) : WebSocketContext
The dispatcher uses this to attach FastRoute path-param attributes to
the stored request BEFORE the actor sees the context — otherwise a
channel actor could not look up $conn->request()->getAttribute('id')
for a route like /ws/games/{id}.
Parameters
- $request : ServerRequestInterface