Skip to main content


A PHP Process manager.


  • A single “primary” PHP instance that’s never killed – it contains the reference filesystem used by all other PHP instances.
  • A pool of disposable PHP instances that are spawned to handle a single request and reaped immediately after.

When a new request comes in, PHPProcessManager yields the idle instance to handle it, and immediately starts initializing a new idle instance. In other words, for n concurrent requests, there are at most n+1 PHP instances running at the same time.

A slight nuance is that the first idle instance is not initialized until the first concurrent request comes in. This is because many use-cases won’t involve parallel requests and, for those, we can avoid eagerly spinning up a second PHP instance.

This strategy is inspired by Cowboy, an Erlang HTTP server. Handling a single extra request can happen immediately, while handling multiple extra requests requires extra time to spin up a few PHP instances. This is a more resource-friendly tradeoff than keeping 5 idle instances at all times.


  • AsyncDisposable






  • [asyncDispose](): Promise<void>
  • Returns Promise<void>


  • Get a PHP instance.

    It could be either the primary PHP instance, an idle disposable PHP instance, or a newly spawned PHP instance – depending on the resource availability.


    when the maximum number of PHP instances is reached and the waiting timeout is exceeded.

    Returns Promise<SpawnedPHP>


  • getPrimaryPhp(): Promise<PHP>
  • Get the primary PHP instance.

    If the primary PHP instance is not set, it will be spawned using the provided phpFactory.


    when called twice before the first call is resolved.

    Returns Promise<PHP>