sovich / simple-server-sent-event
There is no license information available for the latest version (2.2.0) of this package.
Simple "Server Sent Events" based on cache
2.2.0
2024-09-20 20:00 UTC
Requires
- php: ^8.3
- ext-json: *
- psr/cache: *
- symfony/http-foundation: ^4.4|^5.4|^6.0
Requires (Dev)
- cache/array-adapter: ^1.2
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12.4
- phpunit/phpunit: ^11.3.6
- symfony/uid: ^4.4|^5.4|^6.4.11
This package is auto-updated.
Last update: 2024-10-21 08:21:22 UTC
README
Symfony Controller
use Psr\Cache\CacheItemPoolInterface;
use SSE\Response\SSEResponse;
use SSE\Repository\EventStoreRepository;
use SSE\SSEEventListenerFactory;
use Symfony\Component\Routing\Annotation\Route;
#[Route(path: '/listener')]
final class TransactionSSEController
{
public function __invoke(CacheItemPoolInterface $cacheItemPool): SSEResponse
{
$eventStoreRepository = new EventStoreRepository($cacheItemPool);
$factory = new SSEEventListenerFactory($eventStoreRepository);
$sse = $factory->create(
events: ['eventName'],
maxTimeoutWithoutResponse: 60,
pingInterval: 15,
maxExecutionTime: 300,
);
return new SSEResponse($sse, 500000);
}
}
Push event
use SSE\Event\Event;
use SSE\Repository\EventStoreRepository;
use SSE\SSEEventDispatcher;
$eventStoreRepository = new EventStoreRepository($cacheItemPool);
$event = new Event(uniqid(), 'eventName', 'Patient update');
(new SSEEventDispatcher($eventStoreRepository))->dispatch($event);