Skip to content

Commit 311eb57

Browse files
committed
Add readme
1 parent 904b4cc commit 311eb57

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
```

0 commit comments

Comments
 (0)