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

sabre/event

Lightweight PHP 8.2+ library for event-driven development: EventEmitter, promises, an event loop, and coroutines. Used to build reactive, non-blocking apps and services. Full docs at sabre.io/event.

View on GitHub
Deep Wiki
Context7
## Product Decisions This Supports
- **Build vs. Buy**: **Buy** – Eliminates the need to build custom event-driven architectures (e.g., real-time systems, CLI async workflows) from scratch. The package’s **EventEmitter, Promises, Event Loop, and Coroutines** provide a **batteries-included** solution for PHP 8.2+ projects, reducing development time and technical debt by **30–50%** compared to custom implementations.
  - *Example*: Replace ad-hoc `pcntl`/`pthreads` code or ReactPHP integrations with a **type-safe, maintained** alternative.
- **Feature Enablement**: **Async-first architectures** – Enables **non-blocking I/O**, **real-time systems**, and **decoupled microservices** in Laravel or standalone PHP apps. Key use cases:
  - **Real-time APIs/WebSockets**: Build custom HTTP/WebSocket servers (e.g., for live dashboards) without external dependencies like Pusher or Socket.io.
  - **CLI Async Workflows**: Coordinate long-running tasks (e.g., batch processing, API polling) with **coroutines** and **Promises** instead of queues.
  - **Plugin/Extension Systems**: Propagate events dynamically using **wildcard listeners** (`*`) for flexible, decoupled components.
  - **Performance-Critical Pipelines**: Replace synchronous loops or queues for **high-throughput async tasks** (e.g., scraping, data transformation).
- **Roadmap Alignment**: **PHP 8.2+ Migration** – Forces alignment with modern PHP stacks, simplifying future upgrades and reducing legacy maintenance costs. The **strict typing (v6+)** and **PHP 8.2 requirement** ensure compatibility with Laravel’s evolving ecosystem (e.g., `PendingDispatch`, `Laravel 11+`).
- **Cost Optimization**: **Reduces external dependencies** – Avoids licensing costs for tools like Redis (for queues) or Node.js (for async logic) by leveraging **native PHP async primitives**.
- **Developer Experience**: **Reduces cognitive load** – Provides a **consistent API** for async patterns (Promises, coroutines) across teams, reducing onboarding time for complex systems.

---

## When to Consider This Package
### **Adopt When:**
| **Criteria**               | **Details**                                                                                                                                                                                                 |
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **PHP 8.2+ Projects**      | Mandatory for new development; **v6.1.0** is the only supported version. Avoids legacy tech debt and leverages modern PHP features (e.g., attributes, typed properties).                          |
| **Non-Blocking I/O Needs**  | Building **WebSocket servers**, **real-time APIs**, or **CLI async workers** where Laravel’s queues/events are insufficient or overkill.                                                                 |
| **Decoupled Async Logic**   | Requiring **Promises**, **Event Loop**, or **Coroutines** outside Laravel’s synchronous flow (e.g., plugins, microservices, or standalone scripts).                                                          |
| **Performance Optimization**| Tasks like **batch processing**, **API polling**, or **streaming** where synchronous code would bottleneck. The **Event Loop** can handle **thousands of concurrent operations** without blocking.          |
| **Replacing Custom Async Code** | Eliminating ad-hoc event systems, `pcntl`/`pthreads`, or ReactPHP for a **maintained, type-safe** alternative with **better PHP 8.2+ support**.                                                           |
| **Plugin/System Extensibility** | Need to support **dynamic event listeners** (e.g., wildcard `*` matching) or **hot-reloadable** components without restarting the app.                                                                   |
| **PHP 8.2 Upgrade Path**   | Part of a **strategic migration** to modern PHP, with **long-term compatibility** guarantees from SabreIO.                                                                                               |

### **Avoid When:**
| **Criteria**               | **Details**                                                                                                                                                                                                 |
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **PHP <8.2**               | Use **v6.0.x** (PHP 7.4–8.1) or **ReactPHP** for legacy stacks. The **PHP 8.2 requirement** is non-negotiable for v6.1.0+.                                                                                     |
| **Laravel’s Queues/Events Suffice** | For most **HTTP workflows**, Laravel’s built-in `Bus` or `Events` are simpler and more integrated. Overkill for **CRUD-heavy** or **synchronous** applications.                                           |
| **Minimal Async Needs**    | One-off scripts or cron jobs don’t justify the complexity. Use **simple Promises** (e.g., `Spatie\Async`) or **synchronous code** instead.                                                                   |
| **Tight Laravel Integration** | The **Event Loop** can **block HTTP requests** if misused (e.g., running in a route). Reserve for **CLI/Artisan commands**, **queues**, or **custom servers**.                                               |
| **No PHP 8.2 Upgrade Path** | Migration costs may outweigh benefits for teams stuck on older PHP versions. Evaluate **ReactPHP** or **custom solutions** as alternatives.                                                                 |
| **Real-Time UI Frameworks** | If using **Livewire**, **Inertia.js**, or **Laravel Echo**, these already handle async—**no need to rebuild** with `sabre/event`.                                                                             |
| **Microservices with gRPC** | For **high-performance RPC**, consider **RoadRunner** or **Swoole** instead of a lightweight Event Loop.                                                                                                     |

---

## How to Pitch It (Stakeholders)
### **For Executives:**
> *"This package **future-proofs** our async capabilities by enforcing **PHP 8.2+**, aligning with Laravel’s roadmap and reducing legacy maintenance costs. It’s a **turnkey solution** for real-time systems (e.g., live dashboards, WebSocket APIs) or high-throughput CLI tools—**cutting dev time by 30–50%** vs. custom async code.
>
> **Key Benefits**:
> - **No external dependencies**: Eliminates costs for Redis (queues) or Node.js (async logic).
> - **Scalable async**: Handles **thousands of concurrent operations** without blocking (e.g., API polling, batch jobs).
> - **Low-risk adoption**: Backed by **SabreIO** (350+ stars), with **enterprise support** available.
> - **PHP 8.2+ requirement** simplifies long-term tech stack upgrades and **reduces security risks** from legacy PHP.
>
> **Use Cases**:
> - **Real-time features**: Live updates for dashboards, collaborative tools, or gaming backends.
> - **CLI automation**: Async task coordination for ETL, scraping, or CI/CD pipelines.
> - **Plugin architectures**: Decoupled event systems for extensible apps (e.g., CMS plugins).
>
> **ROI**: **$X saved** by avoiding custom async development and **$Y in reduced maintenance** from PHP 8.2+ alignment."*

### **For Engineering:**
> **"**sabre/event** is a **modern, type-safe** alternative to ReactPHP or custom async code, but with **better PHP 8.2+ support** and **Laravel compatibility** (when used correctly).
>
> **Why Use It?**
> - **Promises**: Clean async chains with `.then()`/`.otherwise()` (like JavaScript).
> - **Event Loop**: Non-blocking I/O for **WebSocket servers** or **CLI workers** (e.g., `EventLoop::run()`).
> - **Coroutines**: Write async code with `yield` (e.g., `coroutine(function() { yield $promise; })`).
> - **Wildcard Listeners**: Dynamic event matching (`emitter->on('*', ...)`).
>
> **When to Avoid It**:
> - **HTTP routes**: The Event Loop **blocks requests**—use only in **Artisan commands**, **queues**, or **custom servers**.
> - **Simple async**: For one-off tasks, use **Laravel’s queues** or `Spatie\Async`.
> - **PHP <8.2**: Use **v6.0.x** or **ReactPHP** instead.
>
> **Migration Path**:
> 1. **New projects**: Use **v6.1.0** (PHP 8.2+).
> 2. **Legacy (PHP 7.4–8.1)**: Stick with **v6.0.x** or evaluate **ReactPHP**.
> 3. **Laravel HTTP apps**: **Avoid**—stick to queues/events unless building **custom async logic**.
>
> **Example Use Cases**:
> - **WebSocket Server**:
>   ```php
>   $loop = new EventLoop();
>   $emitter = new Emitter();
>   $server = new WebSocketServer($loop, $emitter);
>   $loop->run();
>   ```
> - **CLI Async Worker**:
>   ```php
>   $loop = new EventLoop();
>   coroutine(function() use ($loop) {
>       yield $promise1;
>       yield $promise2;
>       $loop->stop();
>   });
>   $loop->run();
>   ```
>
> **Risks & Mitigations**:
> - **Blocked HTTP**: Run Event Loop **only in non-HTTP contexts** (e.g
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata