Initial commit

This commit is contained in:
Christopher Vagnetoft
2026-03-01 01:11:48 +01:00
commit 1659492009
7 changed files with 1144 additions and 0 deletions

18
examples/example.php Normal file
View 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";