PHP code example of waaseyaa / mercure

1. Go to this page and download the library: Download waaseyaa/mercure library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

waaseyaa / mercure example snippets


public function __construct(string $hubUrl, string $jwtSecret)

// Publish $data (JSON-encoded) to $topic. Returns true on a 2xx hub
// response; false if unconfigured, on cURL failure, or non-2xx.
public function publish(string $topic, array $data): bool

// True only when jwtSecret is non-empty and hubUrl is an https:// URL.
public function isConfigured(): bool

public function register(): void

use Waaseyaa\Mercure\MercurePublisher;

$publisher = new MercurePublisher(
    hubUrl: 'https://hub.example.com/.well-known/mercure',
    jwtSecret: 'your-hub-jwt-secret',
);

if ($publisher->isConfigured()) {
    $publisher->publish('/notes/42', ['status' => 'updated']);
}