File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # EventSource / Server-Sent Events for [ Framework X] ( https://github.com/clue/framework-x )
2+ This package is an experimental implementation of Server-Sent Events for ` clue/framework-x ` . It doesn't require any modifications to the framework.
3+
4+ Feedback is welcome. Hoping to work towards an implementation that can be shipped with Framework X.
5+
6+ ** Example:**
7+ ``` php
8+ <?php
9+
10+ use Devfrey\FrameworkX\EventSource\BufferedEventStream;
11+ use Devfrey\FrameworkX\EventSource\Event;
12+ use Devfrey\FrameworkX\EventSource\EventSourceHandler;
13+
14+ require __DIR__ . '/vendor/autoload.php';
15+
16+ $loop = React\EventLoop\Factory::create();
17+ $app = new FrameworkX\App($loop);
18+
19+ $app->get('/', new EventSourceHandler($loop, $events = new BufferedEventStream()));
20+
21+ // Send a random value every second
22+ $loop->addPeriodicTimer(1.0, function () use ($events) {
23+ $events->send((new Event())->data(mt_rand()));
24+ });
25+
26+ $app->run();
27+ $loop->run();
28+ ```
You can’t perform that action at this time.
0 commit comments