$manager = new \Platformsh\Cli\Util\ProcessManager();
Fork: everything after this will run in a child. The user's shell will
be blocked until the parent is killed.
$manager->fork().
$logFile = 'path/to/logFile';
$log = new \Symfony\Component\Console\Output\StreamOutput(fopen($logFile, 'a'));
Create multiple external processes.
foreach ($commands as $key => $command) {
$process = new \Symfony\Component\Process\Process($command);
$pidFile = 'path/to/pidFile' . $key;
Start the process with the manager.
$manager->startProcess($process, $pidFile, $log);
Report this to the shell.
echo "Started process: " . $process->getCommandLine() . "\n";
}
Kill the parent process to release the shell prompt.
$manager->killParent();
Monitor the external process(es). This keeps them running until the
$pidFile is deleted or they are otherwise stopped.
$manager->monitor();
显示文件
Open project: commerceguys/platform-cli
Class Usage Examples
Property | Type | Description | |
---|---|---|---|
$processes |
Method | Description | |
---|---|---|
fork ( ) | Fork the current PHP process. | |
killParent ( boolean $error = false ) | Kill the parent process. | |
monitor ( Symfony\Component\Console\Output\OutputInterface $log ) | Monitor processes and stop them if their PID file no longer exists. | |
startProcess ( |
Start a managed external process. | |
supported ( ) : boolean |
public static fork ( ) |
public static killParent ( boolean $error = false ) | ||
$error | boolean | Whether the parent process should exit with an error status. |
public monitor ( Symfony\Component\Console\Output\OutputInterface $log ) | ||
$log | Symfony\Component\Console\Output\OutputInterface | A log file as a Symfony Console output object. |
public startProcess ( |
||
$process | The Symfony Process object to manage. | |
$pidFile | string | The path to a lock file which governs the process: if the file is deleted then the process will be stopped in self::monitor(). |
$log | Symfony\Component\Console\Output\OutputInterface | An output stream to which log messages can be written. |
return | integer | The process PID. |