Files
pinecore/src/Http/WorkerRunner.php
pronchev df1d2a58bf Replace ServerStartCommand with WorkerRunner
FrankenPHP workers are PHP files started by the frankenphp binary, not console commands.
Extract the frankenphp_handle_request() loop into Http\WorkerRunner so apps can use it
directly from worker.php. Remove src/Command/ as it's no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 16:22:02 +03:00

36 lines
916 B
PHP

<?php
namespace Pronchev\Pinecore\Http;
use Pronchev\Pinecore\ExceptionHandler;
final class WorkerRunner
{
public function __construct(
private readonly HttpApplication $app,
private readonly ExceptionHandler $exceptionHandler,
) {}
public function run(): void
{
$maxRequests = (int) ($_SERVER['MAX_REQUESTS'] ?? 0);
for ($n = 0; !$maxRequests || $n < $maxRequests; ++$n) {
$keepRunning = frankenphp_handle_request(function (): void {
try {
$this->app->handleRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
} catch (\Throwable $e) {
$this->exceptionHandler->handleException($e);
}
});
$this->app->terminate();
gc_collect_cycles();
if (!$keepRunning) {
break;
}
}
}
}