-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.php
39 lines (31 loc) · 882 Bytes
/
server.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
37
38
39
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use React\EventLoop\Factory;
use React\Http\Server;
use Psr\Http\Message\ServerRequestInterface;
use React\Http\Response;
require __DIR__ . "/vendor/autoload.php";
echo 'Going to instance the loop : ' . PHP_EOL;
$loop = Factory::create();
echo 'Loop instanced : ' . get_class($loop) . PHP_EOL;
$loop->addSignal(SIGINT, $func = function ($signal) use ($loop, &$func) {
$loop->stop();
});
$server = new Server(function (ServerRequestInterface $request) {
return new Response(
200,
array(
'Content-Type' => 'text/plain'
),
"Hello World!\n"
);
});
$socket = new React\Socket\Server("0.0.0.0:8000", $loop);
$server->listen($socket);
try {
$loop->run();
} catch (\Throwable $trowable) {
echo $trowable->getMessage();
}