Process
Process allows command line commands to be run asynchronously., (*1)
Usage
$process = new Process();
$waiter = $process
->cwd("/working/directory") // Set the working directory
->cmd("find") // Set to command to run
->arg(".") // Add an argument
->option("-type", "f") // Add an option and value
->log("/tmp/files.log") // Set the location of the log file
->async() // Set the process to run asynchronously
->run(); // Run the command
// do some other stuff
$waiter->wait(5); // Wait for the process to complete with a timeout of 5 seconds
Process Methods
cwd
void PhilWaters\Process\Process::cwd(string $cwd)
Sets working directory, (*2)
Arguments
- $cwd string - <p>Working directory</p>
cmd
\PhilWaters\Process\Process PhilWaters\Process\Process::cmd(string $cmd)
Sets the command to run, (*3)
Arguments
- $cmd string - <p>Command to run</p>
option
\PhilWaters\Process\Process PhilWaters\Process\Process::option(string $option, string $value, string $separator)
Adds a command option, (*4)
Arguments
- $option string - <p>Option</p>
- $value string - <p>Value</p>
- $separator string - <p>Separator</p>
arg
\PhilWaters\Process\Process PhilWaters\Process\Process::arg(string $arg)
Adds an argument, (*5)
Arguments
- $arg string - <p>Argument</p>
args
\PhilWaters\Process\Process PhilWaters\Process\Process::args($arg)
Adds arguments, (*6)
Arguments
async
\PhilWaters\Process\Process PhilWaters\Process\Process::async()
Configures the process to run asynchronously. The run method will return a waiter instead of the output., (*7)
log
\PhilWaters\Process\Process PhilWaters\Process\Process::log(string $path, \PhilWaters\Process\number $mode)
Sets the path to a log file, (*8)
Arguments
- $path string - <p>Log file path</p>
- $mode PhilWaters\Process\number - <p>Log write mode (FILE_APPEND)</p>
stdin
\PhilWaters\Process\Process PhilWaters\Process\Process::stdin(mixed $stdin, string $type)
Sets STDIN source (file or pipe), (*9)
Arguments
- $stdin mixed - <p>File path or value to pass to STDIN</p>
- $type string - <p>file or pipe</p>
stdout
\PhilWaters\Process\Process PhilWaters\Process\Process::stdout(string $path, string $mode)
Sets STDOUT path, (*10)
Arguments
- $path string - <p>File path</p>
- $mode string - <p>Write mode (FILE_APPEND)</p>
stderr
\PhilWaters\Process\Process PhilWaters\Process\Process::stderr(string $path, string $mode)
Sets STDERR path, (*11)
Arguments
- $path string - <p>File path</p>
- $mode string - <p>Write mode (FILE_APPEND)</p>
env
\PhilWaters\Process\Process PhilWaters\Process\Process::env(array $env)
Sets array of environment variables, (*12)
Arguments
- $env array - <p>Array of environment variables</p>
run
\PhilWaters\Process\Waiter|array PhilWaters\Process\Process::run()
Runs the command, (*13)
buildCommand
string PhilWaters\Process\Process::buildCommand()
Builds command string, (*14)
Waiter Methods
wait
boolean PhilWaters\Process\Waiter::wait(\PhilWaters\Process\number $timeout)
Wait for the process to finish, (*15)
Arguments
- $timeout PhilWaters\Process\number - <p>Number of seconds to wait. Pass null to wait indefinitely or until PHP process exits based on max_execution_time</p>
terminate
void PhilWaters\Process\Waiter::terminate(integer $signal)
Terminates process, (*16)
Arguments
- $signal integer - <p>Kill signal</p>