marko / broadcasting
Realtime broadcasting contracts and channel authorization for Marko Framework
Package info
github.com/marko-php/marko-broadcasting
Type:marko-module
pkg:composer/marko/broadcasting
Requires
- php: ^8.5
- marko/authentication: 0.11.0
- marko/core: 0.11.0
Requires (Dev)
- marko/testing: 0.11.0
- pestphp/pest: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-06 15:40:23 UTC
README
Realtime broadcasting contracts --- send events to everyone watching a channel, with pluggable drivers that hold the connections outside PHP.
Installation
composer require marko/broadcasting
Install a driver as well: marko/broadcasting-mercure or marko/broadcasting-pusher.
Quick Example
use Marko\Authentication\AuthenticatableInterface; use Marko\Broadcasting\Attributes\BroadcastChannel; use Marko\Broadcasting\ChannelAuthorizerInterface; use Marko\Broadcasting\PrivateChannel; $broadcaster->broadcast('shows.42', 'seat.sold', ['seat' => 'A1']); $broadcaster->broadcast(new PrivateChannel('customers.7'), 'order.shipped', ['orderId' => 9]); #[BroadcastChannel('customers.{customerId}')] class CustomerChannelAuthorizer implements ChannelAuthorizerInterface { public function authorize(?AuthenticatableInterface $user, array $params): bool { return (string) $user?->getAuthIdentifier() === $params['customerId']; } }
Presence channels ("who's online") use PresenceChannel with a PresenceChannelAuthorizerInterface that returns a PresenceMember; the Pusher driver supports them.
Documentation
Full usage, API reference, and examples: marko/broadcasting