Search by

marko / broadcasting

markshust

Realtime broadcasting contracts and channel authorization for Marko Framework

Package info

github.com/marko-php/marko-broadcasting

Type:marko-module

pkg:composer/marko/broadcasting

Statistics

Installs: 274

Dependents: 4

Suggesters: 1

Stars: 0

0.16.0 2026-11-30 21:39 UTC

This package is auto-updated.

Last update: 2026-12-01 14:22:20 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