PHPProcessManager
Implements
- AsyncDisposable
Index
Constructors
Methods
Constructors
constructor
Parameters
optionaloptions: ProcessManagerOptions
Returns PHPProcessManager
Methods
[asyncDispose]
Returns Promise<void>
acquirePHPInstance
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.
Returns Promise<SpawnedPHP>
getPrimaryPhp
Get the primary PHP instance.
If the primary PHP instance is not set, it will be spawned using the provided phpFactory.
Returns Promise<PHP>
A PHP Process manager.
Maintains:
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.