EventSource / Server-Sent Events for Framework X
This package is an experimental implementation of Server-Sent Events for clue/framework-x
. It doesn't require any modifications to the framework.
Feedback is welcome. Hoping to work towards an implementation that can be shipped with Framework X.
Example:
<?php
use Devfrey\FrameworkX\EventSource\BufferedEventStream;
use Devfrey\FrameworkX\EventSource\Event;
use Devfrey\FrameworkX\EventSource\EventSourceHandler;
use React\EventLoop\Loop;
require __DIR__ . '/vendor/autoload.php';
$app = new FrameworkX\App();
$app->get('/', new EventSourceHandler($events = new BufferedEventStream()));
// Send a random value every second
Loop::addPeriodicTimer(1.0, function () use ($events) {
$events->send((new Event())->data(mt_rand()));
});
$app->run();