PHP code example of monkeyscloud / monkeyslegion-process
1. Go to this page and download the library: Download monkeyscloud/monkeyslegion-process library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
monkeyscloud / monkeyslegion-process example snippets
use MonkeysLegion\Process\Process;
// Run a command synchronously
$process = new Process(['ls', '-la']);
$result = $process->run();
echo $result->output(); // stdout
echo $result->exitCode(); // 0
var_dump($result->successful); // true (property hook)
use MonkeysLegion\Process\ProcessBuilder;
$result = ProcessBuilder::create('npm', 'install')
->withCwd('/app')
->withEnv(['NODE_ENV' => 'production'])
->withTimeout(120)
->withIdleTimeout(30)
->run();
if ($result->failed) {
echo $result->errorOutput();
}
use MonkeysLegion\Process\CommandLine;
// Injection-safe — arguments are escaped automatically
$cmd = CommandLine::create('git')
->addArg('commit')
->addOption('-m', 'Initial commit')
->addIf($signed, '--gpg-sign');
$process = new Process($cmd->toArray());
$process->mustRun(); // Throws on failure
// Static factory for raw shell commands
$process = Process::fromShellCommandline('cat data.csv | grep error | wc -l');
$result = $process->run();
// Or via builder
$result = ProcessBuilder::shell('ls -la | grep .php')->run();
use MonkeysLegion\Process\Pipeline\ProcessPipeline;
$result = ProcessPipeline::create()
->pipe(['cat', 'access.log'])
->pipe(['grep', '-i', 'error'])
->pipe(['wc', '-l'])
->run();
echo $result->output(); // Final output from wc
echo $result->finalOutput; // Same (property hook)
var_dump($result->successful); // true if all stages passed
// Per-stage debugging
$stage0 = $result->stage(0);
echo $stage0->exitCode();
use MonkeysLegion\Process\PhpProcess;
$process = new PhpProcess(' echo PHP_VERSION;
use MonkeysLegion\Process\Enum\Signal;
$process = new Process(['sleep', '60']);
$process->start();
// Send SIGTERM
$process->signal(Signal::SIGTERM);
// Or by number
$process->signal(15);
use MonkeysLegion\Process\Exception\ProcessTimedOutException;
$process = new Process(['sleep', '30']);
$process->setTimeout(5); // Kill after 5s total
$process->setIdleTimeout(2); // Kill after 2s with no output
try {
$process->run();
} catch (ProcessTimedOutException $e) {
echo $e->isIdleTimeout() ? 'Idle timeout' : 'General timeout';
}