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

Event Loop Laravel Package

revolt/event-loop

Revolt is a rock-solid event loop for concurrent PHP 8.1+ apps using fibers. It enables non-blocking I/O with synchronous code, serving as a minimal, shared scheduler base for libraries like Amp and ReactPHP.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Concurrency: Revolt leverages PHP 8.1+ fibers to enable cooperative multitasking, making it ideal for high-concurrency applications (e.g., WebSocket servers, real-time APIs, or microservices with I/O-bound workloads).
  • Laravel Compatibility: Laravel’s traditional synchronous execution model (e.g., queues, HTTP requests) is not inherently event-loop-friendly, but Revolt can be integrated to offload blocking operations (e.g., database queries, HTTP calls) into fibers.
  • Non-Blocking I/O: Revolt’s event loop avoids thread blocking, critical for scaling Laravel under high load (e.g., handling thousands of WebSocket connections or long-polling requests).
  • Fiber-Based: Unlike Amp/ReactPHP (which use callbacks/promises), Revolt’s suspension-based model aligns with PHP 8.1+ fibers, reducing cognitive load for developers familiar with synchronous code.

Integration Feasibility

  • Laravel’s Synchronous Core: Revolt cannot replace Laravel’s core (e.g., Eloquent, HTTP layer) but can wrap blocking operations (e.g., database drivers, HTTP clients) in fibers.
  • Middleware/Service Layer: Best integrated at the service layer (e.g., wrapping DB::connection() or Http::get() in suspensions) or via Laravel’s event system (e.g., bus:dispatch with fiber-aware queues).
  • Existing Libraries: Revolt works with Laravel’s built-in components (e.g., Illuminate\Support\Facades) but requires adapters for synchronous APIs (e.g., converting DB::select() to a fiber suspension).
  • Web Server Compatibility: Requires PHP-FPM + Revolt extensions (e.g., revolt/uv) for high-performance I/O. Apache/Nginx + PHP-FPM may need tuning (e.g., pm.max_children, pm.start_servers).

Technical Risk

Risk Area Severity Mitigation Strategy
Fiber Leaks High Enforce suspension resumption in cleanup hooks (e.g., register_shutdown_function).
Blocking Laravel Core High Isolate Revolt to non-critical paths (e.g., background jobs, WebSocket handlers).
PHP Version Lock Medium Requires PHP 8.1+; may block upgrades if Laravel lags.
Debugging Complexity Medium Fibers add stack trace complexity; use FiberLocal for context logging.
Extension Dependencies Medium revolt/uv or revolt/libuv needed for high-performance I/O.
State Management Low Use FiberLocal for request-scoped data (e.g., auth tokens).

Key Questions

  1. Where to Integrate?
    • Should Revolt wrap database queries, HTTP clients, or both?
    • Can Laravel’s queue system (e.g., bus:dispatch) be fiber-aware?
  2. Performance Tradeoffs
    • Will fiber context switches outweigh the benefits for low-concurrency workloads?
    • How does Revolt compare to Laravel Horizon (for queues) or Swoole (for coroutines)?
  3. Error Handling
    • How to propagate fiber exceptions to Laravel’s exception handler (App\Exceptions\Handler)?
    • What happens if a fiber never resumes (e.g., infinite loop)?
  4. Deployment
    • Does the team have experience with PHP-FPM + event loops?
    • Are Revolt extensions (uv, libuv) compatible with the hosting environment?
  5. Long-Term Viability
    • Is Revolt actively maintained (last release: 2026-05-16)?
    • How does it compare to Amp/ReactPHP for Laravel use cases?

Integration Approach

Stack Fit

  • PHP 8.1+ Required: Laravel 9+ (PHP 8.1+) is a hard requirement.
  • Laravel Components:
    • Database: Wrap DB::connection() in fiber suspensions (e.g., Revolt\EventLoop\Suspension).
    • HTTP: Replace Http::get() with Revolt\Http\Client (if available) or a custom fiber wrapper.
    • Queues: Integrate with bus:dispatch via a fiber-aware queue worker.
    • WebSockets: Use Revolt’s WebSocket server (if extending beyond Laravel’s Echo).
  • Extensions:
    • revolt/uv (default) or revolt/libuv for high-performance I/O.
    • revolt/pcntl for multi-process support (if needed).

Migration Path

Phase Actionable Steps Risks
Proof of Concept 1. Replace a single blocking call (e.g., DB::select()) with a fiber suspension. Limited scope; may not show scalability.
Service Layer 2. Wrap database/HTTP clients in fiber-aware services. Breaking changes if APIs aren’t suspension-friendly.
Event System 3. Integrate with Laravel’s events/listeners (e.g., Event::dispatch in fibers). Event listeners may not be fiber-safe.
WebSocket API 4. Replace Echo/Pusher with Revolt’s WebSocket server. Requires custom middleware.
Queue Workers 5. Rewrite workers to use fiber suspensions (e.g., bus:work --fiber). May need custom queue driver.

Compatibility

  • Laravel Core: Not compatible out-of-the-box (e.g., Eloquent, HTTP middleware).
  • Third-Party Packages:
    • Suspension-Friendly: Libraries using Revolt\EventLoop\Suspension (e.g., revolt/http).
    • Callback-Based: Require adapters (e.g., ReactPHPRevolt).
  • Database Drivers:
    • PDO/MySQLi: Can be wrapped in suspensions.
    • Eloquent: May need custom query builder support.

Sequencing

  1. Start Small: Replace one blocking operation (e.g., a slow API call) with a fiber.
  2. Isolate Critical Paths: Focus on high-latency endpoints (e.g., WebSocket handlers).
  3. Add Observability: Use FiberLocal to log fiber context (e.g., request ID).
  4. Benchmark: Compare throughput vs. memory usage against synchronous Laravel.
  5. Gradual Rollout: Deploy to non-critical services first (e.g., background jobs).

Operational Impact

Maintenance

  • Debugging:
    • Stack Traces: Fibers add nested stack frames; use Fiber::getCurrent() for context.
    • Leak Detection: Monitor for unresumed suspensions (e.g., EventLoop::getSuspensions()).
  • Logging:
    • Use FiberLocal to attach request IDs or correlation IDs to logs.
    • Example:
      $fiberLocal = new FiberLocal();
      $fiberLocal->set('request_id', $request->id);
      
  • Error Handling:
    • Centralize fiber exceptions in a global error handler:
      EventLoop::setErrorHandler(fn (Throwable $e) => report($e));
      

Support

  • Team Skills:
    • Requires fiber/async programming knowledge (unlike traditional Laravel).
    • Training needed for developers unfamiliar with event loops.
  • Vendor Lock-In:
    • Revolt is not Laravel-specific; may need custom glue code.
    • No built-in Laravel integrations (e.g., no RevoltServiceProvider).
  • Community:
    • Limited Laravel-specific docs; rely on Revolt’s official docs.

Scaling

  • Horizontal Scaling:
    • Revolt reduces blocking, but PHP-FPM tuning is still critical (e.g., pm.max_children).
    • Stateless fibers scale better than stateful ones (e.g., avoid FiberLocal for session data).
  • Vertical Scaling:
    • Memory Usage: Fibers have lower overhead than threads but still require monitoring.
    • CPU Bound Work: Offload to separate processes (e.g., pcntl_fork).
  • Load Testing:
    • Test with high concurrency (e.g., 10K WebSocket connections).
    • Compare latency
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope