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
Requires
- php: >=7.4|^8.0
- ext-json: *
- psr/cache: *
- symfony/http-foundation: ^4.4|^5.4|^6.0
- symfony/uid: ^4.4|^5.4|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- phpstan/phpstan: ^1
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);