Add some error and exit handling for the server file.
This commit is contained in:
parent
5c72cdbfd5
commit
1de8da8691
@ -1,5 +1,6 @@
|
|||||||
|
APP_PORT=8000
|
||||||
DEPLOYMENT_ENV="development"
|
DEPLOYMENT_ENV="development"
|
||||||
DATABASE_HOST="localhost"
|
DATABASE_HOST="db"
|
||||||
DATABASE_USER="slovocast"
|
DATABASE_USER="slovocast"
|
||||||
DATABASE_PASSWORD="Password01"
|
DATABASE_PASSWORD="Password01"
|
||||||
DATABASE_SCHEMA="slovocast"
|
DATABASE_SCHEMA="slovocast"
|
||||||
|
@ -1,17 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once '../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use Slovocast\Bootstrap;
|
use Slovocast\Bootstrap;
|
||||||
use React\Http\HttpServer;
|
use React\Http\HttpServer;
|
||||||
use React\Socket\SocketServer;
|
use React\Socket\SocketServer;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
try {
|
||||||
$app = Bootstrap::init();
|
$app = Bootstrap::init();
|
||||||
|
|
||||||
$http = new HttpServer(fn (Request $request) => $app->handle($request));
|
$http = new HttpServer(fn (Request $request) => $app->handle($request));
|
||||||
$address = "127.0.0.1:8000";
|
$address = "127.0.0.1:8000";
|
||||||
$socket = new SocketServer($address);
|
$socket = new SocketServer($address);
|
||||||
$http->listen($socket);
|
$http->listen($socket);
|
||||||
|
|
||||||
echo "Server running at $address" . PHP_EOL;
|
$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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,12 +59,14 @@ class Bootstrap
|
|||||||
{
|
{
|
||||||
$config = new Configuration();
|
$config = new Configuration();
|
||||||
$dotenv = \DotenvVault\DotenvVault::createImmutable(APP_ROOT_DIR);
|
$dotenv = \DotenvVault\DotenvVault::createImmutable(APP_ROOT_DIR);
|
||||||
|
$dotenv->safeLoad();
|
||||||
|
|
||||||
// set all configuration details
|
// set all configuration details
|
||||||
$config->addSchema('site', SiteInformationSchema::getSchema());
|
$config->addSchema('site', SiteInformationSchema::getSchema());
|
||||||
$config->addSchema('database', DatabaseConnectionSchema::getSchema());
|
$config->addSchema('database', DatabaseConnectionSchema::getSchema());
|
||||||
$config->addSchema('session', SessionSchema::getSchema());
|
$config->addSchema('session', SessionSchema::getSchema());
|
||||||
|
|
||||||
|
|
||||||
$config->merge([
|
$config->merge([
|
||||||
'site' => [
|
'site' => [
|
||||||
'name' => "Slovocast",
|
'name' => "Slovocast",
|
||||||
@ -77,10 +79,11 @@ class Bootstrap
|
|||||||
'name' => 'slovocast'
|
'name' => 'slovocast'
|
||||||
],
|
],
|
||||||
'database' => [
|
'database' => [
|
||||||
'host' => '127.0.0.1',
|
'host' => $_SERVER['DB_HOST'],
|
||||||
'database' => 'slovocast',
|
'database' => $_SERVER['DB_DATABASE'],
|
||||||
'username' => 'slovocast',
|
'username' => $_SERVER['DB_USERNAME'],
|
||||||
'password' => 'Password01',
|
'password' => $_SERVER['DB_PASSWORD'],
|
||||||
|
'port' => $_SERVER['DB_PORT'],
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -1,20 +1,16 @@
|
|||||||
FROM php:8.3-alpine
|
ARG PHP_VERSION=8.3
|
||||||
|
|
||||||
# Install PHP extensions
|
|
||||||
RUN apk add --no-cache zip libzip-dev \
|
|
||||||
&& docker-php-ext-install pdo_mysql zip
|
|
||||||
|
|
||||||
# Install composer
|
|
||||||
RUN curl -sS https://getcomposer.org/installer | php \
|
|
||||||
&& mv composer.phar /usr/bin/composer
|
|
||||||
|
|
||||||
# Install xdebug
|
|
||||||
RUN apk add --no-cache $PHPIZE_DEPS
|
|
||||||
# && pecl install xdebug-2.7.1 \
|
|
||||||
# && docker-php-ext-enable xdebug \
|
|
||||||
# && echo 'xdebug.remote_enable=1' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
|
||||||
|
|
||||||
|
FROM chialab/php:${PHP_VERSION}
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./app /app
|
COPY app .
|
||||||
|
RUN composer install \
|
||||||
|
--ignore-platform-reqs \
|
||||||
|
--no-interaction \
|
||||||
|
--no-plugins \
|
||||||
|
--prefer-dist \
|
||||||
|
--no-progress \
|
||||||
|
--optimize-autoloader
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD [ "php", "server/server.php" ]
|
CMD [ "php", "server/server.php" ]
|
||||||
|
@ -15,8 +15,8 @@ services:
|
|||||||
app:
|
app:
|
||||||
build:
|
build:
|
||||||
dockerfile: ./deploy/php/Dockerfile
|
dockerfile: ./deploy/php/Dockerfile
|
||||||
volumes:
|
ports:
|
||||||
- ./app:/app
|
- "8000:8000"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
slovocast_db:
|
slovocast_db:
|
||||||
|
Loading…
Reference in New Issue
Block a user