PHPackages                             ntavelis/mercure-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ntavelis/mercure-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ntavelis/mercure-php
====================

Publish messages to mercure hub

v2.0.0(3mo ago)3016.9k—3.6%3[1 PRs](https://github.com/ntavelis/mercure-php/pulls)MITPHPPHP &gt;=8.3CI passing

Since Aug 26Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/ntavelis/mercure-php)[ Packagist](https://packagist.org/packages/ntavelis/mercure-php)[ Docs](https://github.com/ntavelis/mercure-php)[ RSS](/packages/ntavelis-mercure-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (14)Versions (23)Used By (0)

Mercure-php
===========

[](#mercure-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e24fc9c13c1ef45f8145032270c77da0e3deefac128c7013809dd6e52c42abdc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e746176656c69732f6d6572637572652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ntavelis/mercure-php)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![CI](https://github.com/ntavelis/mercure-php/workflows/CI/badge.svg)](https://github.com/ntavelis/mercure-php/workflows/CI/badge.svg)[![codecov](https://camo.githubusercontent.com/dcad59e8da5ca196dc7180cc9702e8e11523d4a874da1e7dd39d351674eadf1c/68747470733a2f2f636f6465636f762e696f2f67682f6e746176656c69732f6d6572637572652d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ntavelis/mercure-php)

This package publishes notifications to the mercure hub from your php application. These messages can be later consumed from the clients(web-browsers or mobile apps) to provide real-time updates to your application. All of this is possible due to the Mercure protocol, you can read more about the protocol [here](https://github.com/dunglas/mercure/blob/master/spec/mercure.md).

Shoutout to [dunglas](https://github.com/dunglas) for his work in the [mercure project](https://github.com/dunglas/mercure/blob/master/spec/mercure.md).

Requirements
------------

[](#requirements)

- PHP 8.3+

Install
-------

[](#install)

Install the package via Composer

```
composer require ntavelis/mercure-php
```

Mercure Hub installation
------------------------

[](#mercure-hub-installation)

The mercure hub which is a binary written in GO Lang, should be up and running, in order to accept the messages from the php application.

Please refer to the [official documentation](https://mercure.rocks/docs/hub/install) on how to Install the hub:

Sending a public notification
-----------------------------

[](#sending-a-public-notification)

We need to publish messages from our php server to the mercure hub and then consume them in our client, in this example in a browser via javascript.

### PHP code

[](#php-code)

The below example is a controller in the Symfony framework:

```
