nexus-runtime-fiber
PHP 8.1+ native Fiber runtime for Nexus — cooperative multitasking with no extensions required.
What's in this package
FiberRuntime— implementsRuntime; manages a map ofFiberinstances and aFiberScheduler;run()enters a tick loopFiberMailbox—SplQueue-backed mailbox;dequeueBlocking()suspends the current fiber until a message arrivesFiberScheduler— sorted timer queue;scheduleOnce,scheduleRepeatedly,advanceTimersFiberCancellable— boolean-flag cancellation handle
Install
composer require nexus-actors/runtime-fiber
Quick example
src/bootstrap.php
use Monadial\Nexus\Core\Actor\ActorSystem;
use Monadial\Nexus\Core\Actor\Behavior;
use Monadial\Nexus\Core\Actor\Props;
use Monadial\Nexus\Runtime\Fiber\FiberRuntime;
use Monadial\Nexus\Runtime\Duration;
$runtime = new FiberRuntime();
$system = ActorSystem::create('app', $runtime);
$ref = $system->spawn(Props::fromBehavior(Behavior::receive(
static fn($ctx, $msg): Behavior => Behavior::same(),
)), 'worker');
$ref->tell(new MyMessage());
$runtime->scheduleOnce(Duration::millis(100), fn() => $system->shutdown(Duration::seconds(1)));
$system->run();
Each actor runs in its own PHP Fiber. The runtime tick loop starts and resumes fibers, then advances the scheduler. Use nexus-runtime-swoole for production workloads requiring true async I/O.
See also
- nexus-runtime —
Runtimeinterface,Duration, and mailbox contracts - nexus-runtime-swoole — Swoole coroutine runtime for production
- nexus-runtime-step — deterministic step runtime for tests