Initial commit
This commit is contained in:
18
examples/example.php
Normal file
18
examples/example.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
$http = new React\Http\HttpServer(
|
||||
function (Psr\Http\Message\ServerRequestInterface $request) {
|
||||
$events = new NoccyLabs\React\Sse\EventSource();
|
||||
echo "Start timer...\n";
|
||||
$t = React\EventLoop\Loop::addPeriodicTimer(1, fn() => $events->sendMessage(date("Y-m-d H:i:s P")));
|
||||
$events->on("close", function () use ($t) {
|
||||
echo "Stop timer...\n";
|
||||
React\EventLoop\Loop::cancelTimer($t);
|
||||
});
|
||||
return $events->response();
|
||||
}
|
||||
);
|
||||
$http->listen(new React\Socket\TcpServer("127.0.0.1:4444"));
|
||||
echo "Go ahead and curl http://127.0.0.1:4444\n";
|
||||
Reference in New Issue
Block a user