Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Runtime Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Decoupling Global State: Symfony Runtime aligns perfectly with Laravel’s evolving architecture, particularly for modular monoliths or microservices. It replaces Laravel’s traditional public/index.php (which relies on $_SERVER, $_ENV, and global state) with a runtime-agnostic bootstrap layer, enabling:
    • Explicit dependency injection (e.g., replacing $_ENV['APP_DEBUG'] with injected config).
    • Runtime isolation (e.g., HTTP vs. CLI vs. worker contexts without shared globals).
    • Framework-agnostic execution (critical for serverless/Lambda deployments where PHP-FPM assumptions fail).
  • Symfony Ecosystem Synergy: Laravel 10+ already uses Symfony components (e.g., HttpClient, Mailer). Symfony Runtime complements this by standardizing bootstrapping, reducing friction for teams adopting Symfony’s DI container or API Platform.
  • Laravel-Specific Gaps:
    • Laravel’s Service Provider model (e.g., 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).
    • Artisan CLI integration is mature, but worker/queue runtimes (e.g., RoadRunner) may need custom adapters.

Integration Feasibility

  • Low-Code Entry Point: Replace 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();
    
    • Zero config for basic use; minimal for customization (e.g., overriding project_dir).
  • Laravel-Specific Challenges:
    • Kernel Initialization: Laravel’s Kernel assumes $_SERVER/$_ENV. Runtime must delegate these to injected services (e.g., Request, Config).
    • Middleware: Global state in middleware (e.g., $request->server->get('HTTP_HOST')) requires refactoring to injected dependencies (e.g., HostResolverInterface).
    • Event Listeners: Listeners using $_ENV or $_SERVER must be updated to use Symfony’s ParameterBag or Laravel’s Config.
  • Tooling Compatibility:
    • Laravel Mix/Vite: Unaffected (runtime operates at the PHP layer).
    • Horizon/Queues: Requires custom runner for worker processes (e.g., RoadRunner adapter).
    • Testing: Eliminates flaky tests caused by global state (e.g., $_ENV pollution in ServiceProvider tests).

Technical Risk

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.

Key Questions for TPM

  1. Global State Audit:

    • "Which Laravel components (middleware, providers, listeners) currently rely on $_SERVER/$_ENV? Can we quantify the refactoring effort?"
    • Tool Suggestion: Run phpstan --level max with rules for global functions or use roave/security-advisories to detect indirect global state usage.
  2. Runtime Diversity:

    • "Are we targeting HTTP-only, or do we need CLI/worker support (e.g., RoadRunner, Lambda)?"
    • Impact: Worker support requires custom runner adapters (e.g., RoadRunnerRuntime).
  3. Laravel Version:

    • "Are we on Laravel 10+? If not, what’s the upgrade path (Symfony Runtime v7.x supports PHP 7.2+, but Laravel 9.x may need polyfills)."
  4. Testing Strategy:

    • "How do we handle legacy tests that assume global state? Can we use Runtime’s TestRuntime for isolated test environments?"
  5. Deployment Strategy:

    • "Can we A/B test Runtime in staging before full rollout? What’s the fallback plan if global state refactoring uncovers critical bugs?"
  6. Team Readiness:

    • "Does the team have experience with Symfony components? If not, what’s the training/ramp-up plan for Runtime’s DI and runtime concepts?"
  7. Long-Term Vision:

    • "Is this a stepping stone to microservices, or is it primarily for compliance/security?"
    • Impact: Microservices require deeper runtime customization (e.g., per-service bootstrapping).

Integration Approach

Stack Fit

  • Laravel 10+: Native compatibility (Symfony Runtime v8.x aligns with Laravel’s PHP 8.2+ requirement).
  • Laravel 9.x: Possible with v7.x, but may require polyfills for Symfony 6.x dependencies.
  • PHP 8.4+: Recommended for v8.x (FrankenPHP auto-detection, PHP 8.4 features).
  • Alternate Runtimes:
    • RoadRunner: First-class support via FrankenPHPRunner auto-detection.
    • AWS Lambda/Bref: Requires custom LambdaRuntime (example: Bref’s Symfony integration).
    • Cloudflare Workers: Experimental; may need WebAssembly (WASM) PHP (e.g., PHP-WASM).

Migration Path

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.

Compatibility

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->
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport