2022-08-21 14:19:27 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use Mezzio\Application;
|
|
|
|
use Psr\Container\ContainerInterface;
|
2022-08-26 15:59:27 +03:00
|
|
|
use Shlinkio\Shlink\EventDispatcher\RoadRunner\RoadRunnerTaskConsumerToListener;
|
2022-08-21 14:19:27 +03:00
|
|
|
use Spiral\RoadRunner\Http\PSR7Worker;
|
2022-08-27 09:01:57 +03:00
|
|
|
|
|
|
|
use function Shlinkio\Shlink\Config\env;
|
2022-08-21 14:19:27 +03:00
|
|
|
|
|
|
|
(static function (): void {
|
|
|
|
/** @var ContainerInterface $container */
|
|
|
|
$container = include __DIR__ . '/../config/container.php';
|
2022-08-27 09:01:57 +03:00
|
|
|
$rrMode = env('RR_MODE');
|
2022-08-21 14:19:27 +03:00
|
|
|
|
2022-08-26 15:59:27 +03:00
|
|
|
if ($rrMode === 'http') {
|
|
|
|
// This was spin-up as a web worker
|
|
|
|
$app = $container->get(Application::class);
|
2022-08-27 09:01:57 +03:00
|
|
|
$worker = $container->get(PSR7Worker::class);
|
2022-08-26 15:59:27 +03:00
|
|
|
|
|
|
|
while ($req = $worker->waitRequest()) {
|
|
|
|
try {
|
|
|
|
$worker->respond($app->handle($req));
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$worker->getWorker()->error((string) $e);
|
|
|
|
}
|
2022-08-21 14:19:27 +03:00
|
|
|
}
|
2022-08-26 15:59:27 +03:00
|
|
|
} else {
|
|
|
|
$container->get(RoadRunnerTaskConsumerToListener::class)->listenForTasks();
|
2022-08-21 14:19:27 +03:00
|
|
|
}
|
|
|
|
})();
|