35 lines
1012 B
PHP
35 lines
1012 B
PHP
<?php
|
|
|
|
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
|
|
|
use Slovocast\Bootstrap;
|
|
use React\Http\HttpServer;
|
|
use React\Socket\SocketServer;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
try {
|
|
$app = Bootstrap::init();
|
|
$http = new HttpServer(fn (Request $request) => $app->handle($request));
|
|
$address = "0.0.0.0";
|
|
$port = "8000";
|
|
$socket = new SocketServer($address . ":" . $port);
|
|
|
|
$http->on('error', function ($error) use ($socket) {
|
|
fprintf(STDERR, $error->getMessage() . "\n");
|
|
fprintf(STDERR, "Closing socket connection.\n");
|
|
$socket->close();
|
|
});
|
|
|
|
$http->on('exit', function () use ($socket) {
|
|
fprintf(STDOUT, "Closing socket connection.\n");
|
|
$socket->close();
|
|
});
|
|
|
|
$http->listen($socket);
|
|
fprintf(STDOUT, "Server running on %s\n", $address);
|
|
} catch (\Exception $e) {
|
|
fprintf(STDERR, "Error caught bootstrapping the application\n");
|
|
fprintf(STDERR, $e->getMessage() . "\n");
|
|
return -1;
|
|
}
|