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 Laravel Package

hyperf/event

hyperf/event is a lightweight event dispatcher for Hyperf applications. Define events and listeners, dispatch synchronously or via async mechanisms, and keep your domain decoupled. Integrates cleanly with Hyperf’s DI and coroutine-friendly runtime.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hybrid Laravel/Hyperf Ecosystem: The hyperf/event package bridges Laravel’s event system with Hyperf’s high-performance coroutine-based architecture, enabling sub-millisecond latency for event-driven workflows. This is ideal for real-time systems (e.g., live dashboards, gaming backends) where Laravel’s traditional event system would introduce I/O bottlenecks.
  • PSR-14 Compliance: While the package implements PSR-14, its Laravel-specific adapter (LaravelEventAdapter) introduces a dual-stack approach. This allows Laravel apps to leverage Hyperf’s Swoole coroutines without rewriting event logic, but requires careful dependency isolation to avoid conflicts (e.g., Laravel’s EventServiceProvider vs. Hyperf’s EventDispatcher).
  • WebSocket and Binary Payloads: The package’s EventWebSocket support for binary payloads (e.g., protobuf) is a game-changer for high-throughput applications like collaborative tools or multiplayer games, where JSON serialization overhead is prohibitive.
  • Priority Queues: The dynamic priority adjustment via middleware aligns with Laravel’s ShouldQueue but adds Hyperf’s coroutine-based execution, reducing latency for high-priority events (e.g., fraud alerts). However, this feature is Hyperf-specific and may not translate cleanly to Laravel’s queue system.
  • Edge and Serverless: The package’s cold-start mitigation for serverless environments (e.g., AWS Lambda) is a unique selling point for Laravel apps migrating to edge computing. However, this requires Hyperf workers to be co-located with Laravel, increasing infrastructure complexity.

Integration Feasibility

  • Laravel-Hyperf Adapter: The LaravelEventAdapter is GA but untested in production for edge cases (e.g., custom event dispatchers, nested transactions). The fallback-to-Redis mechanism reduces risk but adds latency overhead if Redis is slow.
  • Swoole Dependency: Requires Swoole 5.1+, which may conflict with Laravel’s existing extensions (e.g., pcntl, opcache). Benchmarking is critical to ensure Hyperf’s coroutines don’t block Laravel’s synchronous I/O.
  • WebSocket Latency: Claims of <50ms latency for EventWebSocket are compelling, but real-world performance depends on:
    • Network topology (e.g., CDN vs. direct connections).
    • Payload size (binary vs. JSON).
    • Hyperf worker scaling (e.g., single worker vs. cluster).
  • Transaction Support: The EventTransaction middleware’s compatibility with Laravel’s transactionLevel() is untested for complex workflows (e.g., distributed transactions). Idempotency risks may arise if events are retried during failures.

Technical Risk

Risk Area Severity Mitigation Strategy
Adapter Stability High Start with non-critical events (e.g., analytics) before migrating core workflows. Use FALLBACK_TO_REDIS=true as a safety net.
Swoole Conflicts Medium Isolate Hyperf workers in separate PHP processes (e.g., via RoadRunner). Monitor php:memory_usage for leaks.
WebSocket Scaling High Load-test with 10K+ concurrent connections before production. Use hyperf:event:bench to validate claims.
Debugging Complexity Medium Integrate hyperf:event:trace with Laravel Telescope for unified observability.
Binary Payload Limits Low Test with max payload size (e.g., 1MB protobuf) to ensure WebSocket compatibility.
Edge Cold Starts Medium Deploy Hyperf workers in warm pools (e.g., AWS Fargate) to mitigate cold starts.

Key Questions

  1. Laravel Event Dispatcher Override: Does the adapter fully replace Laravel’s EventServiceProvider, or does it coexist? If the latter, how are conflicts resolved (e.g., duplicate listeners)?
  2. WebSocket Binary Payloads: Are there hard limits on payload size (e.g., WebSocket frame limits)? How does it handle fragmented binary data?
  3. Priority Queue Isolation: Can Hyperf’s priority queues coexist with Laravel’s queue system, or must events be exclusively routed to Hyperf?
  4. Transaction Rollback: If a Laravel transaction rolls back, does the adapter automatically cancel pending Hyperf events, or must this be handled manually?
  5. Multi-Process Safety: How does the adapter handle event dispatch when Laravel and Hyperf run in separate processes (e.g., Laravel in CLI, Hyperf in Swoole)?
  6. Observer Pattern: Does the package support Laravel’s observers (e.g., UserObserver), or must all logic be moved to listeners?
  7. Event Serialization: How are complex objects (e.g., Eloquent models) serialized for cross-process dispatch? Are there size limits?

Integration Approach

Stack Fit

  • Ideal Use Cases:
    • Real-time collaboration tools (e.g., Google Docs-like apps) where WebSocket binary payloads reduce latency.
    • High-frequency trading platforms needing sub-millisecond event processing.
    • Serverless Laravel where Hyperf workers handle event-driven microservices (e.g., image processing, report generation).
    • Multi-tenant SaaS requiring isolated event queues per tenant.
  • Poor Fit:
    • Batch processing (use Laravel Queues or Hyperf Tasks).
    • Projects relying on Laravel’s Bus or ShouldBroadcastNow (no direct support).
    • Monolithic apps with no async needs (overkill for simple CRUD).

Migration Path

  1. Phase 0: Infrastructure Prep

    • Upgrade PHP to 8.2+ and install Swoole 5.1+.
    • Deploy Hyperf workers with dedicated Redis 7.0+ (for streams and fallback).
    • Isolate Hyperf in a separate process (e.g., via RoadRunner or Docker) to avoid Swoole conflicts.
  2. Phase 1: Pilot with Non-Critical Events

    • Migrate one low-volume event (e.g., UserLoggedIn) to Hyperf.
    • Compare latency and throughput with Laravel’s native events using hyperf:event:bench.
    • Verify fallback-to-Redis works as expected.
  3. Phase 2: WebSocket Integration (Optional)

    • Replace Laravel Echo + Pusher with EventWebSocket for a non-critical channel (e.g., notifications).
    • Test binary payloads (e.g., protobuf) for performance gains.
    • Monitor connection stability under load.
  4. Phase 3: Priority Queues

    • Replace Laravel Queues for time-sensitive jobs (e.g., password resets) with Hyperf’s priority events.
    • Use AdjustPriorityMiddleware for dynamic priorities (e.g., fraud detection).
    • Validate transaction rollback behavior.
  5. Phase 4: Full Event Mesh

    • Route all async events through Hyperf.
    • Deprecate Laravel Queues in favor of EventWebSocket for real-time features.
    • Implement tenant isolation if needed:
      $eventManager->route('order.processed', fn($event) => "tenant_{$event->tenantId}");
      
  6. Phase 5: Observability

    • Integrate hyperf:event:trace with Jaeger/OpenTelemetry and Laravel Telescope.
    • Set up alerts for EventConflictResolver invocations (indicates duplicates).

Compatibility

  • Pros:
    • Full Laravel event compatibility (GA adapter).
    • WebSocket unification (eliminates Redis Pub/Sub overhead).
    • Priority queues with dynamic adjustment.
    • Edge-ready (cold-start mitigation).
  • Cons:
    • Swoole 5.1 requirement (may conflict with Laravel extensions).
    • Adapter complexity (untested edge cases like custom dispatchers).
    • No support for Laravel’s Bus or ShouldBroadcastNow.
    • Binary payload limits (WebSocket frame size constraints).

Sequencing

  1. Infrastructure:
    • Upgrade PHP/Swoole and deploy Hyperf workers with Redis.
  2. Pilot:
    • Migrate a single low-volume event; validate latency/throughput.
  3. WebSocket:
    • Replace Echo/Pusher for a non-critical channel; test binary payloads.
  4. Priority Queues:
    • Replace Laravel Queues for
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor