PHP Class Platformsh\Cli\Util\ProcessManager

Usage: $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

Protected Properties

Property Type Description
$processes Symfony\Component\Process\Process[]

Public Methods

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 ( Process $process, string $pidFile, Symfony\Component\Console\Output\OutputInterface $log ) : integer Start a managed external process.
supported ( ) : boolean

Method Details

fork() public static method

Code run after this method is run in a child process. The parent process merely waits for a SIGCHLD (successful) or SIGTERM (error) signal from the child. This depends on the PCNTL extension.
public static fork ( )

killParent() public static method

Kill the parent process.
public static killParent ( boolean $error = false )
$error boolean Whether the parent process should exit with an error status.

monitor() public method

Monitor processes and stop them if their PID file no longer exists.
public monitor ( Symfony\Component\Console\Output\OutputInterface $log )
$log Symfony\Component\Console\Output\OutputInterface A log file as a Symfony Console output object.

startProcess() public method

Start a managed external process.
public startProcess ( Process $process, string $pidFile, Symfony\Component\Console\Output\OutputInterface $log ) : integer
$process Symfony\Component\Process\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.

supported() public static method

public static supported ( ) : boolean
return boolean

Property Details

$processes protected_oe property

protected Process[],Symfony\Component\Process $processes
return Symfony\Component\Process\Process[]