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>
This commit is contained in:
35
src/Http/WorkerRunner.php
Normal file
35
src/Http/WorkerRunner.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user