class Channel

Traits

Properties

protected ChannelConnectionManager $connections

The channel connections.

protected int $membershipOperations

The number of membership operations currently publishing shared state.

Methods

array
__serialize()

Prepare the channel instance values for serialization.

void
__unserialize(array $values)

Restore the channel after serialization.

__construct(string $name)

Create a new channel instance.

string
name()

Get the channel name.

array
connections()

Get all connections for the channel.

find(Connection $connection)

Find a connection.

findById(string $id)

Find a connection by its ID.

void
subscribe(Connection $connection, string|null $auth = null, string|null $data = null, string|null $userId = null)

Subscribe to the given channel.

subscribeToChannel(Connection $connection, array $attributes, string|null $userId = null)

Publish and commit a channel subscription.

array
decodeSubscriptionData(string|null $data)

Decode subscription data into connection attributes.

void
afterSubscribed(Connection $connection, SubscriptionResult $result)

Complete side effects for a committed subscription.

void
handleChannelOccupied(Connection $connection, SharedState $sharedState)

Handle channel occupied — dispatch events, check disconnect smoothing.

void
unsubscribe(Connection $connection, string|null $userId = null)

Unsubscribe from the given channel.

unsubscribeFromChannel(Connection $connection, string|null $userId = null)

Publish and commit a channel unsubscription.

void
afterUnsubscribed(Connection $connection, SubscriptionResult $result)

Complete side effects for a committed unsubscription.

void
handleChannelVacated(Connection $connection)

Handle channel vacated — dispatch events and clean up shared locks.

void
dispatchSubscriptionCountWebhook(Connection $connection, SubscriptionResult $result)

Dispatch the subscription_count webhook if enabled and not throttled.

bool
subscribed(Connection $connection)

Determine if the connection is subscribed to the channel.

void
removeIfIdle(Connection $connection)

Remove this exact channel when no local membership work remains.

void
broadcast(array $payload, Connection|null $except = null)

Send a message to all connections subscribed to the channel.

void
broadcastToAll(array $payload)

Send a broadcast to all connections.

void
sendToConnections(string $message, Connection|null $except = null)

Send a message to every selected local connection.

void
broadcastInternally(array $payload, Connection|null $except = null)

Broadcast a message triggered from an internal source.

array
data()

Get the data associated with the channel.

Details

in SerializesChannels at line 16
array __serialize()

Prepare the channel instance values for serialization.

Return Value

array

in SerializesChannels at line 26
void __unserialize(array $values)

Restore the channel after serialization.

Parameters

array $values

Return Value

void

at line 39
__construct(string $name)

Create a new channel instance.

Parameters

string $name

at line 47
string name()

Get the channel name.

Return Value

string

at line 57
array connections()

Get all connections for the channel.

Return Value

array

at line 65
ChannelConnection|null find(Connection $connection)

Find a connection.

Parameters

Connection $connection

Return Value

ChannelConnection|null

at line 73
ChannelConnection|null findById(string $id)

Find a connection by its ID.

Parameters

string $id

Return Value

ChannelConnection|null

at line 83
void subscribe(Connection $connection, string|null $auth = null, string|null $data = null, string|null $userId = null)

Subscribe to the given channel.

Presence channels pass the userId for global refcount tracking.

Parameters

Connection $connection
string|null $auth
string|null $data
string|null $userId

Return Value

void

at line 101
protected SubscriptionResult|null subscribeToChannel(Connection $connection, array $attributes, string|null $userId = null)

Publish and commit a channel subscription.

Parameters

Connection $connection
array $attributes
string|null $userId

Return Value

SubscriptionResult|null

at line 133
protected array decodeSubscriptionData(string|null $data)

Decode subscription data into connection attributes.

Parameters

string|null $data

Return Value

array

at line 143
protected void afterSubscribed(Connection $connection, SubscriptionResult $result)

Complete side effects for a committed subscription.

Parameters

Connection $connection
SubscriptionResult $result

Return Value

void

at line 155
protected void handleChannelOccupied(Connection $connection, SharedState $sharedState)

Handle channel occupied — dispatch events, check disconnect smoothing.

Parameters

Connection $connection
SharedState $sharedState

Return Value

void

at line 199
void unsubscribe(Connection $connection, string|null $userId = null)

Unsubscribe from the given channel.

Presence channels pass the userId for global refcount tracking.

Parameters

Connection $connection
string|null $userId

Return Value

void

at line 213
protected SubscriptionResult|null unsubscribeFromChannel(Connection $connection, string|null $userId = null)

Publish and commit a channel unsubscription.

Parameters

Connection $connection
string|null $userId

Return Value

SubscriptionResult|null

at line 240
protected void afterUnsubscribed(Connection $connection, SubscriptionResult $result)

Complete side effects for a committed unsubscription.

Parameters

Connection $connection
SubscriptionResult $result

Return Value

void

at line 252
protected void handleChannelVacated(Connection $connection)

Handle channel vacated — dispatch events and clean up shared locks.

Parameters

Connection $connection

Return Value

void

at line 292
protected void dispatchSubscriptionCountWebhook(Connection $connection, SubscriptionResult $result)

Dispatch the subscription_count webhook if enabled and not throttled.

Fires on every subscribe/unsubscribe for non-presence channels. Throttled to once per 5 seconds for channels with >100 subscribers.

Parameters

Connection $connection
SubscriptionResult $result

Return Value

void

at line 327
bool subscribed(Connection $connection)

Determine if the connection is subscribed to the channel.

Parameters

Connection $connection

Return Value

bool

at line 335
protected void removeIfIdle(Connection $connection)

Remove this exact channel when no local membership work remains.

Parameters

Connection $connection

Return Value

void

at line 347
void broadcast(array $payload, Connection|null $except = null)

Send a message to all connections subscribed to the channel.

Parameters

array $payload
Connection|null $except

Return Value

void

at line 366
void broadcastToAll(array $payload)

Send a broadcast to all connections.

Parameters

array $payload

Return Value

void

at line 379
protected void sendToConnections(string $message, Connection|null $except = null)

Send a message to every selected local connection.

Parameters

string $message
Connection|null $except

Return Value

void

at line 406
void broadcastInternally(array $payload, Connection|null $except = null)

Broadcast a message triggered from an internal source.

Parameters

array $payload
Connection|null $except

Return Value

void

at line 414
array data()

Get the data associated with the channel.

Return Value

array