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:
19
CLAUDE.md
19
CLAUDE.md
@@ -35,7 +35,7 @@ HTTP → Caddy (:80) → /worker.php → FrankenPHP worker loop
|
|||||||
| Path | Purpose |
|
| Path | Purpose |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `src/Kernel.php` | One-time bootstrap |
|
| `src/Kernel.php` | One-time bootstrap |
|
||||||
| `src/Http/` | `HttpApplication`, `Request`, `Response`, `Router`, `RouteDefinition`, `MiddlewarePipeline`, `HttpException` |
|
| `src/Http/` | `HttpApplication`, `WorkerRunner`, `Request`, `Response`, `Router`, `RouteDefinition`, `MiddlewarePipeline`, `HttpException` |
|
||||||
| `src/Console/` | `ConsoleApplication`, `ConsoleRouter`, `ConsoleInput`, `ConsoleOutput`, `ConsoleDefinition` |
|
| `src/Console/` | `ConsoleApplication`, `ConsoleRouter`, `ConsoleInput`, `ConsoleOutput`, `ConsoleDefinition` |
|
||||||
| `src/Auth/` | `JwtService`, `AuthMiddleware`, `AuthContext`, `AuthException`, `UserProviderInterface` |
|
| `src/Auth/` | `JwtService`, `AuthMiddleware`, `AuthContext`, `AuthException`, `UserProviderInterface` |
|
||||||
| `src/Log/` | `StdoutLogger`, `FileLogger`, `CompositeLogger`, `NullLogger` |
|
| `src/Log/` | `StdoutLogger`, `FileLogger`, `CompositeLogger`, `NullLogger` |
|
||||||
@@ -45,6 +45,23 @@ HTTP → Caddy (:80) → /worker.php → FrankenPHP worker loop
|
|||||||
| `src/Config.php` | Static config loader: `Config::get('section.key')` |
|
| `src/Config.php` | Static config loader: `Config::get('section.key')` |
|
||||||
| `src/ContainerFactory.php` | Builds PHP-DI container from `config/services.php` |
|
| `src/ContainerFactory.php` | Builds PHP-DI container from `config/services.php` |
|
||||||
|
|
||||||
|
## Worker entrypoint
|
||||||
|
|
||||||
|
FrankenPHP запускается бинарником (`frankenphp run --config Caddyfile`), который сам стартует PHP-воркеры. `worker.php` приложения должен:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Pronchev\Pinecore\Kernel;
|
||||||
|
use Pronchev\Pinecore\Http\WorkerRunner;
|
||||||
|
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
Kernel::boot(__DIR__);
|
||||||
|
Kernel::container()->get(WorkerRunner::class)->run();
|
||||||
|
```
|
||||||
|
|
||||||
|
`WorkerRunner` резолвится через DI autowiring, конфигурировать не нужно.
|
||||||
|
`MAX_REQUESTS` env var ограничивает число запросов на воркер (0 = без лимита).
|
||||||
|
|
||||||
## HTTP
|
## HTTP
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Pronchev\Pinecore\Command;
|
namespace Pronchev\Pinecore\Http;
|
||||||
|
|
||||||
use Pronchev\Pinecore\ExceptionHandler;
|
use Pronchev\Pinecore\ExceptionHandler;
|
||||||
use Pronchev\Pinecore\Http\HttpApplication;
|
|
||||||
use Pronchev\Pinecore\Console\ConsoleInput;
|
|
||||||
use Pronchev\Pinecore\Console\ConsoleOutput;
|
|
||||||
|
|
||||||
final class ServerStartCommand
|
final class WorkerRunner
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly HttpApplication $app,
|
private readonly HttpApplication $app,
|
||||||
private readonly ExceptionHandler $exceptionHandler,
|
private readonly ExceptionHandler $exceptionHandler,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(ConsoleInput $input, ConsoleOutput $output): int
|
public function run(): void
|
||||||
{
|
{
|
||||||
$maxRequests = (int) ($_SERVER['MAX_REQUESTS'] ?? 0);
|
$maxRequests = (int) ($_SERVER['MAX_REQUESTS'] ?? 0);
|
||||||
|
|
||||||
@@ -34,7 +31,5 @@ final class ServerStartCommand
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user