Requirements
- PHP 8.6
- Optional:
ext-pcntlfor signal callbacks (Loop::onSignal()) andLoop::fork()
Install
composer require webpatser/fledge-loop
The package conflicts with revolt/event-loop, so the two loops are never installed side by side. Coming from Revolt, rename Revolt\EventLoop to Fledge\Loop and Revolt\EventLoop\X to Fledge\Loop\X.
Choose a driver
The loop picks its driver on first use. FLEDGE_EVENT_LOOP selects it; case and surrounding whitespace are ignored.
| Value | Driver |
|---|---|
auto (default, also when unset or empty) |
PollDriver on kqueue (macOS, BSD) or epoll (Linux); StreamSelectDriver where neither exists |
poll |
PollDriver; throws when neither kqueue nor epoll is available |
select |
StreamSelectDriver, the rollback (limited to descriptors below FD_SETSIZE, usually 1024) |
Any other value throws a Fledge\Loop\UnknownDriverException at the loop's first use.
To choose in code, call Fledge\Loop::install() during the process's own setup, before the loop has run anything:
Fledge\Loop::install('poll');
Without an argument it reads the environment variable. It refuses while the loop is running or has callbacks registered, with a Fledge\Loop\LoopStateException.
Debug mode
Assertions active (zend.assertions=1) or a truthy FLEDGE_DEBUG turn on a check for streams closed while a callback is still enabled. FLEDGE_DEBUG is read once, when the driver is created.
Run the tests
The suite runs with assertions enabled and throwing, because the drivers assert their invariants. A guard test fails when assertions are off.
composer test # php -d zend.assertions=1 -d assert.exception=1 vendor/bin/pest --no-coverageFLEDGE_EVENT_LOOP=select composer test # the same on StreamSelectDrivercomposer analyse # PHPStan
Next: Quick start.