Symfony Mercure Component

Fund package maintenance!

Installs: 6 607 627

Dependents: 24

Suggesters: 1

Security: 0

Stars: 403

Watchers: 7

Forks: 39

Open Issues: 8

v0.6.4 2023-12-03 22:09 UTC

This package is auto-updated.

Last update: 2024-02-03 22:31:56 UTC


Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast, reliable and battery-efficient way. It is especially useful to publish real-time updates of resources served through web APIs, to reactive web and mobile apps.

The Mercure Component implements the "publisher" part of the Mercure Protocol.

Getting Started

$ composer require symfony/mercure
// change these values accordingly to your hub installation
define('HUB_URL', '');
define('JWT', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.LRLvirgONK13JgacQ_VbcjySbVhkSmHy3IznH3tA9PM');

use Symfony\Component\Mercure\Hub;
use Symfony\Component\Mercure\Jwt\StaticTokenProvider;
use Symfony\Component\Mercure\Update;

$hub = new Hub(HUB_URL, new StaticTokenProvider(JWT));
// Serialize the update, and dispatch it to the hub, that will broadcast it to the clients
$id = $hub->publish(new Update('', 'Hi from Symfony!'));