~/docs
Resonate
Resonate
0.x 0.1.0, current
Fledge Loop
Toggle sidebar
Fledge Loop
webpatser/fledge-loop 0.1.0

Fledge Loop 0.x

Installation

Install Fledge Loop with Composer, pick a driver and run the test suite.

Requirements

  • PHP 8.6
  • Optional: ext-pcntl for signal callbacks (Loop::onSignal()) and Loop::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-coverage
FLEDGE_EVENT_LOOP=select composer test # the same on StreamSelectDriver
composer analyse # PHPStan

Next: Quick start.