Symfony Runtime

Decouples PHP applications from global state and framework bootstrapping conventions

Library
Composer
vv8.0.14
740stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity72
Maintenance80
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture85
Code Quality82
Innovation78
Learning Curve55

Symfony Runtime is the small abstraction layer that decides how a PHP application actually gets executed — reading $_SERVER, wiring up error handlers, loading .env files, and dispatching to the right runner for CLI commands, HTTP kernels, or FrankenPHP workers. Instead of every entry-point script (public/index.php, bin/console) hard-coding bootstrap logic and reaching into superglobals, an application exposes a single callable that returns an app object, and Runtime figures out the rest.

Because the bootstrapping contract is just “return a callable, get back a RunnerInterface,” any PHP project — not only full Symfony applications — can adopt it via the generic GenericRuntime implementation, while SymfonyRuntime adds awareness of symfony/console, symfony/http-foundation, symfony/http-kernel, and symfony/dotenv when those components are present. This makes applications easier to test (no global state to fake) and portable across execution environments, including long-running FrankenPHP worker processes.

What You Get

  • A GenericRuntime that works with plain PHP callables returning array $context, array $argv, or array $request, with zero framework dependency
  • A SymfonyRuntime that auto-detects installed Symfony components (console, http-foundation, http-kernel, dotenv) and injects the right argument types
  • Automatic .env file loading via symfony/dotenv integration, including override and extra-path support
  • Built-in FrankenPhpWorkerRunner support for long-running worker processes, including configurable request-count restarts and kernel reset
  • A Composer plugin that wires the generated autoload_runtime.php entry point automatically on install

Common Use Cases

  • Bootstrapping a Symfony application’s public/index.php and bin/console without repeating environment/error-handler setup
  • Writing framework-agnostic PHP scripts that still get .env loading, debug-aware error handling, and typed argument injection
  • Running Symfony HTTP kernels or console applications inside FrankenPHP worker mode for persistent, low-latency request handling
  • Testing application logic in isolation by injecting fake runtimes/resolvers instead of relying on global PHP state

Under The Hood

Architecture - The design centers on two cooperating interfaces: ResolverInterface, which reflects on the app callable’s parameters and resolves matching arguments, and RunnerInterface, which decides how to actually execute the resolved app (as a closure return, an HTTP response, a console command, or a FrankenPHP worker loop). GenericRuntime implements the base contract using only PHP superglobals and reflection; SymfonyRuntime extends it, adding a resolveType() override that recognizes Request, Application, Command, and InputInterface/OutputInterface types when the corresponding Symfony components (http-foundation, console) are installed, and getRunner() dispatches to HttpKernelRunner, ConsoleApplicationRunner, ResponseRunner, or FrankenPhpWorkerRunner in Runner/ based on what the app callable returns. A Composer plugin (Internal/ComposerPlugin.php) generates Internal/autoload_runtime.template into the vendor autoload files at install time, wiring the callable convention into public/index.php/bin/console automatically.

Tech Stack - Pure PHP 8.4+ with no runtime dependencies beyond composer-plugin-api; all Symfony component integrations (symfony/console, symfony/http-foundation, symfony/http-kernel, symfony/dotenv, symfony/dependency-injection) are optional require-dev/soft dependencies detected via class_exists() checks, so the same package works standalone or fully wired into a Symfony app. Tests run on PHPUnit with phpunit.xml.dist configuring the suite.

Code Quality - The codebase is compact (roughly a dozen source files) with PSR-4 autoloading split between Symfony\Component\Runtime\ and an internal Symfony\Runtime\Symfony\Component\ namespace for polyfill-style internals. Tests/SymfonyRuntimeTest.php covers FrankenPHP worker detection edge cases (truthy/falsy env values), custom type resolution overrides, untyped-argument error messages, and loop-max validation with explicit LogicException assertions — indicating deliberate attention to edge cases around environment-variable parsing and error messaging rather than just happy-path coverage. Strict typing (readonly properties, typed constructor arrays with PHPDoc shape annotations) is used throughout.

API Design - The public surface is deliberately minimal: applications interact with Runtime only by returning a callable from their entry point, with argument types resolved via reflection rather than explicit configuration. This keeps boilerplate near zero for simple scripts while still supporting rich typed injection (Request, Command, InputInterface) for full Symfony apps, and the RuntimeInterface/ResolverInterface/RunnerInterface split gives extension points for custom runtimes without needing to fork the base classes.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search