Skip to content

SseEvent

A single Server-Sent Events wire-format message.

final class SseEvent

SourceHttp/Sse/SseEvent.php
PropertyTypeDescription
$datastringreadonly.
$event?``stringreadonly.
$id?``stringreadonly.
$retryMs?``intreadonly.

public function __construct(string $data, ?string $event = null, ?string $id = null, ?int $retryMs = null): mixed

ParameterTypeDescription
$datastring
$event?``string
$id?``string
$retryMs?``int

Returns mixed

MethodDescription
format(): stringRenders the event as its text/event-stream representation.
[`of(stringarray $data, ?string $event = null, ?string $id = null, ?int $retryMs = null): SseEvent`](#of)

public function format(): string

Renders the event as its text/event-stream representation.

The optional event, id and retry fields are emitted first and only when set, then the data, split into one data: line per embedded newline as the wire format requires. The result ends with the blank line that terminates the message.

Returns string

public static function of(string|array<mixed> $data, ?string $event = null, ?string $id = null, ?int $retryMs = null): SseEvent

Arrays are JSON-encoded.

ParameterTypeDescription
$data`string“array<mixed>`
$event?``string
$id?``string
$retryMs?``int

Returns SseEvent