PHPackages                             flyokai/revolt-event-loop - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. flyokai/revolt-event-loop

ActiveLibrary[Queues &amp; Workers](/categories/queues)

flyokai/revolt-event-loop
=========================

Rock-solid event loop for concurrent PHP applications.

v1.0.9(1mo ago)06↓100%MITPHPPHP &gt;=8.1CI failing

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/flyokai/revolt-event-loop)[ Packagist](https://packagist.org/packages/flyokai/revolt-event-loop)[ RSS](/packages/flyokai-revolt-event-loop/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

flyokai/revolt-event-loop
=========================

[](#flyokairevolt-event-loop)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](AGENTS.md)

> Rock-solid cooperative event loop for PHP 8.1+ — fork of [`revolt/event-loop`](https://github.com/revoltphp/event-loop) used as the foundation of every async operation in the Flyokai framework.

This package replaces `revolt/event-loop` (via Composer's `replace`) with a Flyokai-tracked fork that adds `EventLoop::onMysqli()` for the async-mysqli driver. The static API and semantics are otherwise identical to upstream.

> **Heads up.** Most users want upstream `revolt/event-loop`. This package only matters if you depend on Flyokai's `flyokai/laminas-db-driver-async`, which uses `onMysqli()`.

Features
--------

[](#features)

- **Static `EventLoop` accessor** — `defer`, `delay`, `repeat`, `onReadable`, `onWritable`, `onSignal`, `onMysqli`
- **`Suspension` API** — fiber pause/resume via `getSuspension()->suspend()/resume()/throw()`
- **`FiberLocal`** — per-fiber storage backed by `WeakMap`
- **Auto-selected driver** — `UvDriver` &gt; `EvDriver` &gt; `EventDriver` &gt; `StreamSelectDriver`
- **`onMysqli()`** — Flyokai-specific addition: register a callback that fires when a `mysqli` connection running an async query is ready to be reaped

Installation
------------

[](#installation)

```
composer require revolt/event-loop
```

`flyokai/revolt-event-loop` `replace`s `revolt/event-loop`, so the standard package name resolves to this fork inside Flyokai installs.

Quick start
-----------

[](#quick-start)

```
use Revolt\EventLoop;

EventLoop::defer(function () {
    echo "next tick\n";
});

EventLoop::delay(0.5, function () {
    echo "after 500ms\n";
});

$id = EventLoop::repeat(1.0, function () {
    echo "tick\n";
});

EventLoop::run();   // call from {main} only
```

### Suspension from inside a fiber

[](#suspension-from-inside-a-fiber)

```
$suspension = EventLoop::getSuspension();

EventLoop::delay(0.1, fn() => $suspension->resume('done'));

$result = $suspension->suspend();   // 'done'
```

### Async mysqli (the Flyokai addition)

[](#async-mysqli-the-flyokai-addition)

```
$mysqli->query($sql, MYSQLI_ASYNC);

$suspension = EventLoop::getSuspension();

EventLoop::onMysqli($mysqli, function ($watcherId, mysqli $link) use ($suspension) {
    EventLoop::cancel($watcherId);
    $suspension->resume($link->reap_async_query());
});

$result = $suspension->suspend();
```

This is the primitive that `flyokai/laminas-db-driver-async`'s `AsyncMysqli` strategy is built on.

Driver selection
----------------

[](#driver-selection)

Auto-selected by `DriverFactory` in priority order:

1. **`UvDriver`** — `ext-uv` (libuv). Highest performance.
2. **`EvDriver`** — `ext-ev` (libev).
3. **`EventDriver`** — `ext-event` (libevent). Cross-platform.
4. **`StreamSelectDriver`** — pure PHP `stream_select()`. Default fallback. Limited to ~1024 FDs.
5. **`TracingDriver`** — debug wrapper, set `REVOLT_DRIVER_DEBUG_TRACE=1`.

Override with `REVOLT_DRIVER=\Full\Class\Name`.

Tick model
----------

[](#tick-model)

```
Activate queued callbacks
   → Execute defer callbacks
   → Dispatch one timer / signal / stream callback (each)
   → Continue while any referenced callbacks remain

```

Every callback runs in its own fiber. Callbacks must return `null` or `void` — anything else throws `InvalidCallbackError`.

Gotchas
-------

[](#gotchas)

- **PHP version**: requires `>=8.1.17` or `>=8.2.4` (older versions have GC bugs). Override with `REVOLT_DRIVER_SUPPRESS_ISSUE_10496=1`.
- **Callback return**: must be `null`/`void`.
- **`run()` is `{main}` only**. From a fiber, use the `Suspension` API.
- **`fclose()` doesn't auto-cancel** — `cancel()` the callback explicitly.
- **Signals are process-global**. Same signal across drivers is undefined. Requires `ext-pcntl`.
- **`StreamSelectDriver` FD ceiling** — ~1024. Install `ext-uv`/`ext-ev`/`ext-event` to raise it.
- **WeakMap fiber refs** — circular references in user code can collect a fiber unexpectedly during GC.
- **Dead `{main}` suspension** — if the loop exits without resuming `{main}`, the suspension is permanently invalid.
- **Error handler must handle or re-throw** — exceptions inside the error handler halt the loop immediately.

License
-------

[](#license)

MIT — Copyright (c) 2021- Revolt (Aaron Piotrowski, Cees-Jan Kiewiet, Christian Lück, Niklas Keller, and contributors). See `LICENSE`.

See also
--------

[](#see-also)

- [`flyokai/laminas-db-driver-async`](../laminas-db-driver-async/README.md) — `AsyncMysqli` consumer of `onMysqli()`
- Upstream:  — for non-Flyokai projects, use `revolt/event-loop` directly.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~205 days

Total

3

Last Release

42d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/247743048?v=4)[flyokai](/maintainers/flyokai)[@flyokai](https://github.com/flyokai)

---

Top Contributors

[![kelunik](https://avatars.githubusercontent.com/u/2743004?v=4)](https://github.com/kelunik "kelunik (63 commits)")[![trowski](https://avatars.githubusercontent.com/u/1628287?v=4)](https://github.com/trowski "trowski (29 commits)")[![flyokai](https://avatars.githubusercontent.com/u/247743048?v=4)](https://github.com/flyokai "flyokai (6 commits)")[![Nevay](https://avatars.githubusercontent.com/u/22509671?v=4)](https://github.com/Nevay "Nevay (2 commits)")[![danog](https://avatars.githubusercontent.com/u/7339644?v=4)](https://github.com/danog "danog (2 commits)")[![wtsergo](https://avatars.githubusercontent.com/u/305326?v=4)](https://github.com/wtsergo "wtsergo (1 commits)")[![azjezz](https://avatars.githubusercontent.com/u/29315886?v=4)](https://github.com/azjezz "azjezz (1 commits)")[![xjaja](https://avatars.githubusercontent.com/u/5057757?v=4)](https://github.com/xjaja "xjaja (1 commits)")[![bwoebi](https://avatars.githubusercontent.com/u/3154871?v=4)](https://github.com/bwoebi "bwoebi (1 commits)")[![nhedger](https://avatars.githubusercontent.com/u/649677?v=4)](https://github.com/nhedger "nhedger (1 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (1 commits)")[![tnsoftbear](https://avatars.githubusercontent.com/u/2427839?v=4)](https://github.com/tnsoftbear "tnsoftbear (1 commits)")

---

Tags

eventevent-loopasyncasynchronousschedulerconcurrencynon-blocking

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flyokai-revolt-event-loop/health.svg)

```
[![Health](https://phpackages.com/badges/flyokai-revolt-event-loop/health.svg)](https://phpackages.com/packages/flyokai-revolt-event-loop)
```

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k130.2M400](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92550.1M204](/packages/revolt-event-loop)[icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

1.1k152.2k14](/packages/icicleio-icicle)[recoil/recoil

Asynchronous coroutines for PHP 7.

79062.4k7](/packages/recoil-recoil)[clue/reactphp-flux

Flux, the lightweight stream processor to concurrently do many (but not too many) things at once, built on top of ReactPHP.

59124.1k1](/packages/clue-reactphp-flux)[recoil/react

Integrate Recoil with ReactPHP.

32283.0k12](/packages/recoil-react)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
