Channel
class Channel
Traits
Properties
| protected ChannelConnectionManager | $connections | The channel connections. |
|
| protected int | $membershipOperations | The number of membership operations currently publishing shared state. |
Methods
Create a new channel instance.
Get the channel name.
Get all connections for the channel.
Find a connection by its ID.
Subscribe to the given channel.
Publish and commit a channel subscription.
Decode subscription data into connection attributes.
Complete side effects for a committed subscription.
Handle channel occupied — dispatch events, check disconnect smoothing.
Publish and commit a channel unsubscription.
Complete side effects for a committed unsubscription.
Handle channel vacated — dispatch events and clean up shared locks.
Dispatch the subscription_count webhook if enabled and not throttled.
Remove this exact channel when no local membership work remains.
Send a message to all connections subscribed to the channel.
Send a broadcast to all connections.
Send a message to every selected local connection.
Broadcast a message triggered from an internal source.
Get the data associated with the channel.
Details
in
SerializesChannels at line 16
array
__serialize()
Prepare the channel instance values for serialization.
in
SerializesChannels at line 26
void
__unserialize(array $values)
Restore the channel after serialization.
at line 39
__construct(string $name)
Create a new channel instance.
at line 47
string
name()
Get the channel name.
at line 57
array
connections()
Get all connections for the channel.
at line 65
ChannelConnection|null
find(Connection $connection)
Find a connection.
at line 73
ChannelConnection|null
findById(string $id)
Find a connection by its ID.
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.
at line 101
protected SubscriptionResult|null
subscribeToChannel(Connection $connection, array $attributes, string|null $userId = null)
Publish and commit a channel subscription.
at line 133
protected array
decodeSubscriptionData(string|null $data)
Decode subscription data into connection attributes.
at line 143
protected void
afterSubscribed(Connection $connection, SubscriptionResult $result)
Complete side effects for a committed subscription.
at line 155
protected void
handleChannelOccupied(Connection $connection, SharedState $sharedState)
Handle channel occupied — dispatch events, check disconnect smoothing.
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.
at line 213
protected SubscriptionResult|null
unsubscribeFromChannel(Connection $connection, string|null $userId = null)
Publish and commit a channel unsubscription.
at line 240
protected void
afterUnsubscribed(Connection $connection, SubscriptionResult $result)
Complete side effects for a committed unsubscription.
at line 252
protected void
handleChannelVacated(Connection $connection)
Handle channel vacated — dispatch events and clean up shared locks.
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.
at line 327
bool
subscribed(Connection $connection)
Determine if the connection is subscribed to the channel.
at line 335
protected void
removeIfIdle(Connection $connection)
Remove this exact channel when no local membership work remains.
at line 347
void
broadcast(array $payload, Connection|null $except = null)
Send a message to all connections subscribed to the channel.
at line 366
void
broadcastToAll(array $payload)
Send a broadcast to all connections.
at line 379
protected void
sendToConnections(string $message, Connection|null $except = null)
Send a message to every selected local connection.
at line 406
void
broadcastInternally(array $payload, Connection|null $except = null)
Broadcast a message triggered from an internal source.
at line 414
array
data()
Get the data associated with the channel.