-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathstream.php
More file actions
26 lines (20 loc) · 697 Bytes
/
stream.php
File metadata and controls
26 lines (20 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
require __DIR__ . '/../vendor/autoload.php';
if (!isset($argv[1]) || isset($argv[2])) {
exit('Usage error: stream.php <uri>' . PHP_EOL);
}
$es = new Clue\React\EventSource\EventSource($argv[1]);
$es->on('message', function (Clue\React\EventSource\MessageEvent $message) {
// $json = json_decode($message->data);
var_dump($message);
});
$es->on('open', function () {
echo 'open' . PHP_EOL;
});
$es->on('error', function (Exception $e) use ($es) {
if ($es->readyState === Clue\React\EventSource\EventSource::CLOSED) {
echo 'Permanent error: ' . $e->getMessage() . PHP_EOL;
} else {
echo 'Temporary error: ' . $e->getMessage() . PHP_EOL;
}
});