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

Http Kernel Laravel Package

drift/http-kernel

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Async-first Laravel Integration: The drift/http-kernel is a Symfony HttpKernel wrapper with ReactPHP Promise-based async support, making it a strong candidate for Laravel applications requiring non-blocking I/O (e.g., real-time APIs, event-driven workflows, or high-concurrency microservices). It aligns with Laravel’s growing adoption of async features (e.g., Laravel 10’s Swoole/RoadRunner support) but provides a Symfony-compatible abstraction layer.
  • Kernel Replacement: Designed to replace Laravel’s native HttpKernel, enabling async request handling while maintaining compatibility with middleware, controllers, and routing. This is particularly valuable for:
    • High-load APIs (e.g., WebSockets, SSE, or gRPC gateways).
    • Hybrid sync/async workflows (e.g., mixing traditional HTTP with async tasks).
  • DriftPHP Ecosystem: If adopting DriftPHP’s async stack (e.g., drift/async, drift/orm), this kernel acts as a unified entry point, reducing fragmentation.

Integration Feasibility

  • Middleware & Controller Compatibility: Since it extends Symfony’s HttpKernel, it preserves Laravel’s middleware stack (including Illuminate\Pipeline). Controllers and route definitions remain unchanged, but async handlers (e.g., ReactPHP-backed responses) can be introduced.
  • Async Response Handling: Supports Promise-based responses, enabling:
    • Non-blocking database queries (via drift/orm or ReactDBAL).
    • Concurrent HTTP calls (e.g., GuzzleHttp with async clients).
    • Event-driven pipelines (e.g., dispatching async jobs via Laravel Horizon or DriftPHP’s async queue).
  • Routing Layer: Works with Laravel’s router.php but may require custom middleware to bridge sync/async boundaries (e.g., converting Symfony\Component\HttpFoundation\Request to Psr\Http\Message\RequestInterface).

Technical Risk

Risk Area Mitigation Strategy
Middleware Conflicts Test with Laravel’s core middleware (e.g., VerifyCsrfToken, Authenticate).
Async Deadlocks Profile with Xdebug/Tideways to detect blocking calls in async contexts.
Dependency Bloat ReactPHP adds ~10MB to footprint; benchmark memory usage in production-like loads.
Laravel-Specific Gaps Some Laravel features (e.g., Request facade, Response macros) may need adapters.
Debugging Complexity Async stack traces are harder to debug; invest in structured logging (e.g., Monolog + ReactPHP handlers).

Key Questions

  1. Async Use Case Clarity:
    • Is this for real-time APIs (WebSockets/SSE) or background processing (e.g., async job queues)?
    • Will it replace all HTTP requests or only specific routes?
  2. Middleware Overhead:
    • How will sync middleware (e.g., Auth) interact with async handlers?
    • Are there plans to opt into async per route/controller?
  3. Database Layer:
    • Will drift/orm or ReactDBAL be used? If not, how will async DB calls be handled?
  4. Fallback Strategy:
    • What’s the plan for graceful degradation if async fails (e.g., fallback to sync kernel)?
  5. Tooling Support:
    • Does Laravel’s debugbar, Tinker, or Horizon work with this kernel?
    • Are there plans for async-friendly testing (e.g., PestPHP + ReactPHP assertions)?

Integration Approach

Stack Fit

  • Core Compatibility:
    • Laravel 10+: Best fit due to built-in async support (e.g., Swoole/RoadRunner).
    • Symfony 4.3+: Directly compatible; Laravel’s kernel is a Symfony fork.
    • PHP 8.1+: Required for ReactPHP’s Promise features and Laravel’s async improvements.
  • Ecosystem Synergy:
    • DriftPHP Stack: If adopting drift/async, drift/orm, or drift/queue, this kernel provides a unified async layer.
    • ReactPHP: Enables integration with ReactPHP-based libraries (e.g., React\Http, React\Socket).
    • Laravel Async Tools: Can complement Laravel Horizon, Laravel Echo, or Laravel Vapor.

Migration Path

  1. Phase 1: Proof of Concept
    • Replace Laravel’s kernel in a non-critical route (e.g., /async-health).
    • Verify middleware, controllers, and responses work.
    • Test with a ReactPHP-based async task (e.g., delayed response).
  2. Phase 2: Hybrid Integration
    • Use conditional routing to direct async traffic to drift/http-kernel.
    • Example:
      // routes/web.php
      Route::get('/sync', [Controller::class, 'syncMethod']);
      Route::get('/async', [Controller::class, 'asyncMethod'])
           ->middleware('async_kernel'); // Custom middleware to switch kernels
      
    • Implement a kernel resolver (e.g., app/KernelResolver.php) to dynamically select sync/async.
  3. Phase 3: Full Adoption
    • Replace the global kernel in app/Providers/AppServiceProvider.php:
      public function register()
      {
          $this->app->singleton(\Illuminate\Contracts\Http\Kernel::class, function ($app) {
              return new \Drift\HttpKernel\Kernel($app);
          });
      }
      
    • Update event listeners and service providers to handle async contexts.

Compatibility

Component Compatibility Notes
Middleware Most middleware will work, but stateful middleware (e.g., sessions) may need async adapters.
Controllers Standard controllers work; async methods should return PromiseInterface.
Routing Laravel’s router works, but async route handlers require ReactPHP-aware responses.
Validation Illuminate\Validation is sync; use ReactPHP-compatible validators if needed.
Queue Workers Can integrate with drift/queue or Laravel Horizon for async job processing.
Testing PHPUnit tests may need ReactPHP assertions (e.g., await()).

Sequencing

  1. Prerequisites:
    • Upgrade to Laravel 10+ and PHP 8.1+.
    • Install drift/http-kernel and reactphp/promise.
    • Set up a ReactPHP event loop (e.g., React\EventLoop\Factory).
  2. Kernel Replacement:
    • Start with a subset of routes to isolate risks.
    • Gradually expand to high-traffic endpoints.
  3. Async Workflow Adoption:
    • Replace blocking I/O (e.g., DB::select(), Http::get()) with async equivalents.
    • Example:
      use React\Promise\PromiseInterface;
      
      public function asyncMethod(): PromiseInterface
      {
          return \Drift\Async::db()->select('users')->then(function ($users) {
              return response()->json($users);
          });
      }
      
  4. Fallback Mechanism:
    • Implement a circuit breaker for async routes (e.g., fall back to sync kernel on failure).
    • Example:
      try {
          return $asyncKernel->handle($request);
      } catch (AsyncException $e) {
          return $syncKernel->handle($request);
      }
      

Operational Impact

Maintenance

  • Dependency Management:
    • ReactPHP introduces new dependencies (ext-swoole, ext-event, etc.). Monitor for CVE updates.
    • DriftPHP ecosystem may evolve separately from Laravel; stay updated on drift/http-kernel releases.
  • Debugging Complexity:
    • Async stack traces are harder to follow; invest in:
      • Structured logging (e.g., Monolog + ReactPHP handlers).
      • Distributed tracing (e.g., OpenTelemetry with ReactPHP instrumentation).
    • Xdebug may not work seamlessly; use Tideways or Blackfire for profiling.
  • Configuration Overhead:
    • Requires event loop setup (e.g., Swoole, ReactPHP loop).
    • May need custom kernel bootstrapping (e.g., async service providers).

Support

  • Community & Documentation:
    • Limited Laravel-specific docs:
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.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle