Skip to content

Why Nexphant Exists

Traditional PHP was designed for the web of the late 1990s: a simple request comes in, a script executes from top to bottom, outputs HTML, and immediately dies. This "shared-nothing" architecture has served PHP incredibly well, but modern web applications require a fundamentally different foundation.

Modern applications need WebSockets, real-time events, background queues, connection pooling, and sub-millisecond response times. Trying to build these on top of traditional PHP request lifecycles leads to massive architectural friction.

Nexphant exists to solve this friction. It is a persistent runtime architecture for PHP built to bring runtime awareness, lifecycle management, and modern execution semantics to long-running, stateful systems.

The Limitations of Traditional PHP

1. The Bootstrapping Tax

In a traditional PHP setup (FPM/Nginx), every single incoming request pays a boot-up cost. The runtime must:

  • Read, parse, and compile autoloaded PHP files.
  • Initialize framework service providers, configuration, and dependencies.
  • Establish new TCP connections to databases, caches, and key-value stores.
  • Handle the request, serialize the response, and then tear down the entire application environment.

This bootstrapping process can easily consume 15ms to 50ms before your actual application code even begins to run. Under heavy traffic, this boot-up overhead dominates CPU consumption.

2. The Stateless Request Bottleneck

Because everything is destroyed at the end of a request, you cannot maintain state in memory. This introduces several critical limitations:

  • No Connection Pools: Every request must establish its own database connections. This slows down queries and quickly saturates the database connection limits.
  • No Shared Cache: In-memory caches cannot persist between requests without resorting to external stores like Redis.
  • No Background Jobs: You cannot spawn a non-blocking background task to process later; you must push it to an external queue runner and manage a separate queue system.

Long-Running PHP Challenges

Keeping PHP alive across requests solves the bootstrapping tax, but it introduces brand new runtime challenges that traditional PHP frameworks are not equipped to handle:

  • Memory Leaks: A single byte leaked per request will eventually consume all system memory and crash the worker.
  • Socket Pollution: Closed database connections, orphaned sockets, and resource descriptors quickly build up if not cleaned up aggressively.
  • Zombie Fibers: Spawning an asynchronous fiber that hangs indefinitely can cause silent locks and drain scheduler capacity.

Why Async Alone Is Not Enough

Many developers look to async PHP libraries (like ReactPHP or Amp) to solve performance limitations. However, async raw primitives are low-level and lack safety guards.

Without structured concurrency:

  • Spawning asynchronous tasks without a clear owner leads to untrackable lifecycles.
  • If a request gets cancelled by a client disconnect, background tasks spawned by that request continue to run, wasting CPU and leaking memory.
  • Handling exceptions inside concurrent fibers is notoriously error-prone, often leading to unhandled exceptions crashing the entire server process.

The Nexphant Architecture: Runtime-First

The Nexphant runtime is a lifecycle-aware and ownership-aware runtime architecture for PHP. We treat memory safety, cooperative concurrency, and resource tracking as first-class citizens:

mermaid
flowchart TD
    req["HTTP Request"] --> worker["Fiber Worker"]
    worker --> registry["Resource Registry"]
    worker --> context["Parent Context"]
    registry --> cleanup["Automatic LIFO Cleanup"]
    context --> token["Cancellation Token"]
  • Deterministic Ownership: Every connection, socket, and memory allocation is registered to an owner. When the owner completes, the runtime automatically cleans up everything.
  • Cancellation Propagation: If a client drops their connection, the cancellation signal propagates down the entire fiber hierarchy, stopping downstream database calls or external API fetches instantly.
  • Graceful Drain: During deployments, Nexphant finishes running in-flight requests, flushes pending jobs, and shuts down safely without dropping active connections.

IMPORTANT

Bring runtime awareness to PHP. Move beyond raw async performance. Embrace structured concurrency, explicit ownership, and predictable runtime semantics with Nexphant.

Project Mission

Nexphant is developed as an open-source initiative dedicated to advancing persistent runtime architectures for PHP.

Our goal is to build a high-performance, lifecycle-aware environment that unchains PHP from its traditional stateless limitations. We focus on engineering excellence, structured concurrency, and predictable execution semantics to make stateful PHP applications safe, stable, and highly concurrent.

Released under the MIT License.