Fledge Loop runs fibers on an event loop. One static facade, Fledge\Loop, gives you deferred callbacks, delays and repeating timers, stream readiness, signals and suspensions (the await pattern for fibers).
It runs on PHP 8.6's Io\Poll (epoll on Linux, kqueue on macOS and BSD), with a stream_select() driver as the fallback and as a rollback switch. It is safe to fork. It is part of the Fledge family, but it stands on its own and needs nothing beyond PHP.
What you get
- Deferred, delayed and repeating callbacks, each running in its own fiber.
- Stream readiness callbacks (
onReadable(),onWritable()) and signal callbacks (onSignal()). - Suspensions:
suspend()parks the calling fiber while the loop keeps running,resume()wakes it with a value. - Two drivers,
PollDriverandStreamSelectDriver, selected withFLEDGE_EVENT_LOOPorLoop::install(). Loop::fork()andLoop::afterFork()so a forked child starts on a fresh loop.
Where it sits in Fledge
Fledge Loop is the event loop of the Fledge stack. According to the repository, fledge-fiber, the Fledge framework (see Fledge), the Torque queue worker and the Resonate WebSocket server run on it.
Origins
Fledge Loop is derived from revolt/event-loop v1.1.0 (MIT), which grew out of amphp's loop. It is an independent fork for PHP 8.6: the same fibers, suspensions and callbacks, reshaped and optimised for Fledge and maintained on its own. The repository credits the Revolt and amphp projects for the original design. It does not follow revolt/event-loop releases.
The package conflicts with revolt/event-loop on purpose: one loop per process. The namespace mapping is Revolt\EventLoop to Fledge\Loop and Revolt\EventLoop\X to Fledge\Loop\X.
What was left out compared to the original: the Ev, Event, Uv and Tracing drivers, the original's own Io\Poll driver (replaced by Fledge's PollDriver), REVOLT_DRIVER as the way to pick a driver, and support for PHP below 8.6.
Status
Version 0.1.0 is the first release. The API may still change before 1.0; such changes are listed in the changelog.
The package supports only the latest stable PHP release. When a new PHP version is released, the next release of the package requires it and support for the previous version ends. Currently that is PHP 8.6.
Next: Installation.