monadial / nexus-monorepo
Nexus — A production-grade actor system for PHP 8.5+
Package info
Type:project
pkg:composer/monadial/nexus-monorepo
Requires
- php: >=8.5.7
- brick/math: ^0.12
- cuyz/valinor: ^2.3
- doctrine/dbal: ^4.0
- doctrine/orm: ^3.0
- lcobucci/jwt: ^5.0
- nikic/fast-route: ^1.3
- nyholm/psr7: ^1.8
- open-telemetry/api: ^1.9
- open-telemetry/context-swoole: ^1.2
- open-telemetry/exporter-otlp: ^1.4
- open-telemetry/sdk: ^1.14
- open-telemetry/sem-conv: ^1.38
- opis/closure: ^4.0
- psr/clock: ^1.0
- psr/event-dispatcher: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
- psr/simple-cache: ^3.0
- rybakit/msgpack: ^0.9
- symfony/console: ^8.0
- symfony/messenger: ^8.0
- symfony/uid: ^8.0
Requires (Dev)
- deptrac/deptrac: ^4.6
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.32
- maglnet/composer-require-checker: ^4.24
- monolog/monolog: ^3.0
- nette/php-generator: ^4.2
- phpro/grumphp: ^2.19
- phpunit/phpunit: ^13.0
- shipmonk/coverage-guard: ^1.0
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^4.0
- swoole/ide-helper: ^6.0
- symfony/cache: ^8.0.12
- symfony/http-client: ^8.1
- vimeo/psalm: ^6.0
Conflicts
- symfony/yaml: <8.0.12
This package is auto-updated.
Last update: 2026-07-23 14:57:26 UTC
README
An actor system for PHP 8.5+. Type-safe actors, supervision trees, event sourcing, and multi-worker scaling — Akka and OTP patterns in the PHP you already know.
Maturity: Nexus is a pre-1.0 actor-system toolkit under active development. APIs are subject to change, several subsystems are experimental, and the project is not yet production-hardened. Evaluate it accordingly before depending on it for critical workloads.
Why Nexus?
PHP has mature tools for HTTP request handling, but nothing serious for building concurrent, long-running systems. When you need actors, supervision, or message-driven architectures, the answer has always been "use a different language." Nexus changes that.
The problem. Building concurrent PHP systems today means stitching together queue workers, process managers, and ad-hoc error recovery. There's no structured way to manage state across concurrent units, no supervision hierarchy to handle failures automatically, and no type safety for the messages flowing through your system.
The approach. Nexus brings battle-tested patterns from Akka and OTP to PHP with
Psalm-assisted protocol checking. Every ActorRef<T> is generic — with the optional Psalm plugin
and concrete annotations enabled, message type mismatches are caught at analysis time. This is
static analysis, not a runtime guarantee: at runtime boundaries (deserialization, dynamic
dispatch) types are not enforced. Behaviors are immutable value objects. State is explicitly
managed, never shared. The entire API is readonly and final by default.
What makes it different:
- Two runtimes, one core API. Write core actor code once. Run it on PHP Fibers during development and Swoole coroutines in production. Some features are runtime-specific — the worker pool and HTTP server are Swoole-only, and mailbox, shutdown, and cancellation semantics can differ between runtimes.
- Supervision hierarchy. Actors form a hierarchy. Parents supervise children. When something fails, the supervision strategy decides what happens. One-for-one restart directives with retry windows are implemented; all-for-one, escalation, and exponential-backoff strategies are currently incomplete.
- PHP 8.5+ native. Nexus uses
readonly class, typed class constants, and generic templates throughout. Built for modern PHP, not retrofitted onto it. - PSR everywhere. PSR-11 containers, PSR-3 logging, PSR-14 event dispatching, PSR-20 clocks. Nexus plugs into your existing stack.
- Multi-worker scaling. Scale actors across all CPU cores on a single machine via Swoole's
Thread\Pool. Each worker runs an independentActorSystem.WorkerActorRefdelivers messages cross-thread viaThread\Queue— an indicative local microbenchmark measured ~260K msgs/sec per worker pair, but no published methodology exists yet and the committed performance suite is partially broken, so treat that figure as unverified. No application-level serializer is required (Swoole serializes internally).
Quick Example
Two actors communicating with immutable messages using the Fiber runtime:
<?php declare(strict_types=1); use Monadial\Nexus\Core\Actor\{ActorContext, ActorRef, ActorSystem, Behavior, Props}; use Monadial\Nexus\Runtime\Duration; use Monadial\Nexus\Runtime\Fiber\FiberRuntime; readonly class Ping { public function __construct(public ActorRef $replyTo) {} } readonly class Pong {} $ponger = Behavior::receive(static function (ActorContext $ctx, object $msg): Behavior { if ($msg instanceof Ping) { $ctx->log()->info('Ponger received Ping'); $msg->replyTo->tell(new Pong()); } return Behavior::same(); }); $pinger = Behavior::setup(static function (ActorContext $ctx) use ($ponger): Behavior { $pongerRef = $ctx->spawn(Props::fromBehavior($ponger), 'ponger'); $pongerRef->tell(new Ping($ctx->self())); return Behavior::receive(static function (ActorContext $ctx, object $msg): Behavior { if ($msg instanceof Pong) { $ctx->log()->info('Pinger received Pong'); } return Behavior::same(); }); }); $runtime = new FiberRuntime(); $system = ActorSystem::create('ping-pong', $runtime); $system->spawn(Props::fromBehavior($pinger), 'pinger'); $runtime->scheduleOnce(Duration::millis(500), static function () use ($system): void { $system->shutdown(Duration::seconds(1)); }); $system->run();
Features
- Type-safe actors — Psalm Level 1 generics across behaviors, refs, and contexts
- Multiple runtimes — Fiber runtime for development; Swoole runtime for production
- Supervision trees — one-for-one restart strategies with configurable retry limits (all-for-one, escalation, and backoff are incomplete)
- Immutable messages —
readonly classmessage protocol enforced by Psalm plugin - Stashing — buffer messages during transitional states with
$ctx->stash()/$ctx->unstashAll() - Scheduled messages — one-shot and repeating timers via
$ctx->scheduleOnce()/$ctx->scheduleRepeatedly() - Ask pattern — request-response with timeout:
$ref->ask($factory, Duration::millis(200)) - Dead letters — undeliverable messages routed to the dead-letter endpoint
- Persistence and event sourcing — event-sourced actors and durable state actors with pluggable storage (in-memory, DBAL, Doctrine ORM)
- Multi-worker scaling — cross-worker messaging via
Swoole\Thread\Queue(~260K msgs/sec per worker pair in an indicative local microbenchmark; methodology not yet published)
Installation
composer require nexus-actors/core nexus-actors/runtime-fiber
For the Swoole production runtime:
composer require nexus-actors/runtime-swoole
For multi-worker scaling (requires ZTS PHP 8.5+ and Swoole 6.2.1+ with --enable-swoole-thread):
composer require nexus-actors/worker-pool nexus-actors/worker-pool-swoole
For persistence and event sourcing:
composer require nexus-actors/persistence # With Doctrine DBAL storage: composer require nexus-actors/persistence-dbal # With Doctrine ORM storage: composer require nexus-actors/persistence-doctrine
Packages
| Package | Description |
|---|---|
nexus-actors/core |
Behaviors, actors, supervision, mailboxes, and the core API |
nexus-actors/runtime |
Shared runtime abstractions and async primitives (Future, FutureSlot, Runtime) |
nexus-actors/runtime-fiber |
Fiber runtime — actors as PHP fibers with cooperative scheduling |
nexus-actors/runtime-swoole |
Swoole runtime — actors as Swoole coroutines with native channels |
nexus-actors/runtime-step |
Deterministic step runtime for tests — step(), drain(), advanceTime() |
nexus-actors/worker-pool |
Worker pool contracts — WorkerNode, WorkerActorRef, hash ring, transport interfaces |
nexus-actors/worker-pool-swoole |
Swoole thread-based scaling — Thread\Queue transport, Thread\Map directory, WorkerPoolApp |
nexus-actors/cluster |
Remote contracts for future TCP-based multi-machine clustering |
nexus-actors/persistence |
Persistence core — event sourcing, durable state, snapshot strategies, in-memory stores |
nexus-actors/persistence-dbal |
DBAL persistence adapter — Doctrine DBAL-backed event, snapshot, and state stores |
nexus-actors/persistence-doctrine |
Doctrine ORM persistence adapter — entity-based event, snapshot, and state stores |
nexus-actors/serialization |
Valinor-based message serialization with type registry |
nexus-actors/app |
Application layer — declarative actor registration for single-process deployments |
nexus-actors/psalm |
Psalm plugin for generic type inference and actor-protocol static analysis |
nexus-actors/nexus |
Meta-package: core + runtime-fiber + serialization |
Documentation
Full documentation: nexusactors.com
Start with the Nexus thesis:
Requirements
- PHP 8.5+
- Swoole 6.2.1+ compiled with
--enable-swoole-thread(fornexus-worker-pool-swooleonly) - ZTS PHP (for
nexus-worker-pool-swooleonly)
License
MIT