phasync
WebSocket / send

Method

WebSocket::send

Send a text message; nothing happens once the connection is closed.

Description#

public WebSocket::send(
    string $text
): void

May be called from any coroutine; messages from different coroutines never interleave. Waits while the client reads slowly, and gives the client up (closing the connection) after WebSocket::WRITE_TIMEOUT seconds.

Parameters#

$text string
The message, which must be UTF-8

Errors / Exceptions#

ExceptionWhen
ValueErrorWhen $text is not valid UTF-8

Examples#

Example 1
$ws->send(json_encode(['type' => 'welcome']));

See also#