-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
36 lines (30 loc) · 1017 Bytes
/
test.php
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
27
28
29
30
31
32
33
34
35
36
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Socket\Server;
use ReactParallel\FutureToPromiseConverter\FutureToPromiseConverter;
use ReactParallel\Psr15Adapter\ReactMiddleware;
use ReactParallel\Runtime\Runtime;
use WyriHaximus\Psr15\Cat\CatMiddleware;
require_once 'vendor/autoload.php';
$loop = Factory::create();
$socket = new Server('0.0.0.0:1337', $loop);
$http = new \React\Http\Server([
new ReactMiddleware($loop, Runtime::create(new FutureToPromiseConverter($loop)), new CatMiddleware(true)),
static function (ServerRequestInterface $request): ResponseInterface {
return new Response(200, [], 'Hoi!');
}
]);
$http->on('error', function (Throwable $throwable) {
echo $throwable;
});
$http->listen($socket);
$loop->addSignal(SIGINT, function () use ($loop) {
$loop->stop();
});
$loop->addSignal(SIGKILL, function () use ($loop) {
$loop->stop();
});
$loop->run();