sovich/simple-server-sent-event

There is no license information available for the latest version (2.0.0) of this package.

Simple "Server Sent Events" based on cache

2.0.0 2022-10-20 15:22 UTC

This package is auto-updated.

Last update: 2024-04-11 19:45:27 UTC


README

Symfony Controller

use Psr\Cache\CacheItemPoolInterface;
use SSE\SSEEventListenerFactory;
use SSE\SSEResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route("/listener")
 */
final class TransactionSSEController
{
    public function __invoke(CacheItemPoolInterface $cacheItemPool): SSEResponse
    {
        $sse = (new SSEEventListenerFactory($cacheItemPool))->create(['eventName']);

        return new SSEResponse($sse, 500000);
    }
}

Push event

$event = new Event(Ulid::generate(), 'eventName', 'Patient update');
(new SSEEventDispatcher($cacheItemPool))->dispatch($event);