Skip to content

Runtime Overview ​

Bringing Persistent PHP Runtime Awareness ​

Nexphant treats the runtime as the primary architectural layer. It provides a persistent runtime architecture for PHP where fibers, task hierarchies, and connection pools are first-class citizens. Before routing or handling middleware, Nexphant establishes:

  • Structured task hierarchies where fibers, timers, and requests are integrated into a single tree.
  • Deterministic ownership, linking databases, channels, and sockets directly to their execution contexts.
  • Cooperative cancellation propagation and graceful coordination systems.
  • Comprehensive runtime observability primitives.

Persistent Workers ​

PHP processes run continuously. Boot once, handle thousands of requests without restarting.

mermaid
flowchart LR
    Boot["Boot"]
    Warm["Warm up"]
    Handle["Handle requests"]
    Drain["Drain"]
    Stop["Stop"]
    Persistent["Persistent worker<br/>no per-request restart"]

    Boot --> Warm --> Handle --> Drain --> Stop
    Handle -. thousands of requests .-> Handle
    Persistent -. keeps memory warm .-> Warm
    Persistent -. owns runtime loop .-> Handle

Fiber Concurrency ​

Nexphant uses PHP Fibers for cooperative concurrency. Each request runs in its own fiber. Fibers yield on I/O operations, allowing other requests to proceed.

php
// handled in fiber 1
$app->get('/slow', function () {
    sleep(1); // fiber suspends, other requests proceed
    return ['done' => true];
});

Task Lifecycle ​

mermaid
stateDiagram-v2
    [*] --> Spawn
    Spawn --> Running
    Running --> Suspended: I/O wait
    Suspended --> Resumed: I/O ready
    Resumed --> Running
    Running --> Completed
    Completed --> Released: close owned resources
    Released --> [*]

Completed tasks release their owned resources automatically.

Why Long-Running PHP Needs a Safety Model ​

Traditional PHP cleans up automatically — each request dies. Persistent PHP doesn't. Without a safety model:

  • Resources leak across requests
  • Memory grows unbounded
  • One failed request can corrupt state

Nexphant's safety model:

ProblemSolution
Resource leaksOwnership tracking
Runaway requestsCancellation + deadlines
Memory leaksLifecycle + leak detection
Shutdown data lossGraceful drain
Silent failuresObservability

Next Steps ​

Released under the MIT License.