Skip to main content

nexus-runtime-fiber

PHP 8.1+ native Fiber runtime for Nexus — cooperative multitasking with no extensions required.

What's in this package

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