ChildProcess class allows you to spawn and manage child processes from your NativePHP application. You can run system commands, PHP scripts, Node.js scripts, and Artisan commands as separate processes.
Available Methods
start()
Start a new child process with a custom command.The command to execute. Can be a string or an array of command arguments.
A unique identifier for this process. Used to reference the process later.
The working directory for the process. Defaults to your application’s base path.
Environment variables to pass to the process.
Whether the process should restart automatically if it exits.
Returns the ChildProcess instance with populated properties.
php()
Start a PHP script as a child process.The PHP script or command to execute.
A unique identifier for this process.
Environment variables to pass to the PHP process.
Whether the process should restart automatically if it exits.
PHP ini settings to apply to the process (e.g.,
['memory_limit' => '256M']).Returns the ChildProcess instance.
node()
Start a Node.js script as a child process.The Node.js script or command to execute.
A unique identifier for this process.
Environment variables to pass to the Node.js process.
Whether the process should restart automatically if it exits.
Returns the ChildProcess instance.
artisan()
Run an Artisan command as a child process.The Artisan command to execute (without the ‘artisan’ prefix).
A unique identifier for this process.
Environment variables to pass to the Artisan command.
Whether the process should restart automatically if it exits.
PHP ini settings to apply to the process.
Returns the ChildProcess instance.
get()
Retrieve information about a running process by its alias.The alias of the process to retrieve. If called on an instance, defaults to that instance’s alias.
Returns the ChildProcess instance if found, or null if not found.
all()
Retrieve all running child processes.Returns an associative array of ChildProcess instances, keyed by their aliases.
stop()
Stop a running child process.The alias of the process to stop. If called on an instance, defaults to that instance’s alias.
restart()
Restart a running child process.The alias of the process to restart. If called on an instance, defaults to that instance’s alias.
Returns the restarted ChildProcess instance, or null if the process could not be restarted.
message()
Send a message to a running child process.The message to send to the process.
The alias of the process to send the message to. If called on an instance, defaults to that instance’s alias.
Returns the ChildProcess instance for method chaining.
Properties
TheChildProcess class exposes the following readonly properties:
The process ID of the child process.
The unique identifier for this process.
The command that was executed, as an array.
The working directory of the process.
The environment variables passed to the process.
Whether the process is set to restart automatically.
PHP ini settings applied to the process (PHP processes only).