symfony/runtime
Symfony Runtime decouples PHP applications from global state by providing a flexible runtime entry point and bootstrapping layer. It standardizes how apps are started across environments and integrations, improving portability and testability.
public/index.php (which relies on $_SERVER, $_ENV, and global state) with a runtime-agnostic bootstrap layer, enabling:
$_ENV['APP_DEBUG'] with injected config).HttpClient, Mailer). Symfony Runtime complements this by standardizing bootstrapping, reducing friction for teams adopting Symfony’s DI container or API Platform.register(), boot()) often relies on global state. Runtime does not replace this but wraps it, requiring adaptive refactoring (e.g., moving $_ENV access to injected services).public/index.php with a runtime-aware wrapper (e.g., bootstrap/runtime.php):
use Symfony\Component\Runtime\Runner\RunnerInterface;
use Symfony\Component\Runtime\SymfonyRuntime;
$runtime = new SymfonyRuntime();
$runner = $runtime->getRunner();
$runner->run();
project_dir).Kernel assumes $_SERVER/$_ENV. Runtime must delegate these to injected services (e.g., Request, Config).$request->server->get('HTTP_HOST')) requires refactoring to injected dependencies (e.g., HostResolverInterface).$_ENV or $_SERVER must be updated to use Symfony’s ParameterBag or Laravel’s Config.$_ENV pollution in ServiceProvider tests).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Global State Refactoring | High | Use static analysis (PHPStan, Psalm) to detect $_SERVER/$_ENV usage. Prioritize high-impact areas (e.g., middleware, providers). |
| Runtime Fragmentation | Medium | Start with HTTP/CLI (lowest risk), then adopt workers (e.g., RoadRunner) incrementally. |
| Laravel-Specific Quirks | Medium | Test with Laravel’s bootstrap/app.php (where Kernel is instantiated). May need a custom Runtime class to bridge Laravel’s DI. |
| Performance Overhead | Low | Symfony Runtime is optimized for low overhead (benchmarks show <5% latency increase). FrankenPHP auto-detection further reduces cost. |
| Vendor Lock-in | Low | MIT license + Symfony’s maturity (used by API Platform, Symfony itself). No proprietary dependencies. |
| CI/CD Disruption | Medium | Phased rollout: Deploy runtime wrapper in staging first, monitor for global state errors. |
Global State Audit:
$_SERVER/$_ENV? Can we quantify the refactoring effort?"phpstan --level max with rules for global functions or use roave/security-advisories to detect indirect global state usage.Runtime Diversity:
RoadRunnerRuntime).Laravel Version:
Testing Strategy:
TestRuntime for isolated test environments?"Deployment Strategy:
Team Readiness:
Long-Term Vision:
FrankenPHPRunner auto-detection.LambdaRuntime (example: Bref’s Symfony integration).| Phase | Actions | Tools/Dependencies |
|---|---|---|
| Assessment | Audit global state usage ($_SERVER, $_ENV, $_GET, etc.) in middleware, providers, and listeners. |
PHPStan, Psalm, roave/security-advisories, custom regex search. |
| Bootstrap Replacement | Replace public/index.php with bootstrap/runtime.php (Symfony Runtime wrapper). |
Symfony Runtime (symfony/runtime:^8.0), Laravel’s bootstrap/app.php. |
| Dependency Injection | Refactor global state access to injected services (e.g., Request, Config, ServerBag). |
Laravel’s DI container, Symfony’s ParameterBag. |
| Middleware Refactor | Update middleware to use injected dependencies (e.g., HostResolverInterface instead of $_SERVER['HTTP_HOST']). |
Laravel’s Middleware trait, Illuminate\Http\Request. |
| CLI/Worker Support | Extend Runtime for Artisan (SymfonyRuntime::getRunner()) and workers (custom RoadRunnerRuntime or LambdaRuntime). |
symfony/console, spatie/laravel-roadrunner, AWS SDK. |
| Testing | Replace global state in tests with Runtime’s TestRuntime or Laravel’s Testing traits. |
PestPHP, PHPUnit, Laravel’s HttpTestCase. |
| Deployment | Roll out Runtime in staging, monitor for global state errors, then promote to production. | Feature flags (e.g., Laravel’s config('app.runtime_enabled')), canary releases. |
| Component | Compatibility | Notes |
|---|---|---|
| Laravel Kernel | High (with refactoring). Runtime delegates to bootstrap/app.php, but $_SERVER/$_ENV access in Kernel must be injected. |
Use SymfonyRuntime::getKernel() with custom Kernel subclass. |
| Middleware | Medium. Global state in middleware (e.g., `$request->server-> |
How can I help you explore Laravel packages today?