2024-06-20 02:20:42 +00:00
|
|
|
<?php
|
|
|
|
|
2024-07-20 02:16:04 +00:00
|
|
|
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
2024-06-20 02:20:42 +00:00
|
|
|
|
|
|
|
use Slovocast\Bootstrap;
|
|
|
|
use React\Http\HttpServer;
|
|
|
|
use React\Socket\SocketServer;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
|
2024-11-15 00:51:53 +00:00
|
|
|
/**
|
|
|
|
* We should only be using this method of deploying the applications once we
|
|
|
|
* figure out how to pool MySQL connections. While most PHP can be used in an
|
|
|
|
*/
|
2024-07-20 01:37:37 +00:00
|
|
|
try {
|
|
|
|
$app = Bootstrap::init();
|
|
|
|
$http = new HttpServer(fn (Request $request) => $app->handle($request));
|
2024-07-22 00:51:19 +00:00
|
|
|
$address = "0.0.0.0";
|
|
|
|
$port = "8000";
|
|
|
|
$socket = new SocketServer($address . ":" . $port);
|
2024-07-20 01:37:37 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
});
|
|
|
|
|
2024-07-20 02:16:04 +00:00
|
|
|
$http->listen($socket);
|
2024-07-20 01:37:37 +00:00
|
|
|
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;
|
|
|
|
}
|