Process allows command line commands to be run asynchronously.
$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
void PhilWaters\Process\Process::cwd(string $cwd)
Sets working directory
- Visibility: public
- $cwd string - <p>Working directory</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::cmd(string $cmd)
Sets the command to run
- Visibility: public
- $cmd string - <p>Command to run</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::option(string $option, string $value, string $separator)
Adds a command option
- Visibility: public
- $option string - <p>Option</p>
- $value string - <p>Value</p>
- $separator string - <p>Separator</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::arg(string $arg)
Adds an argument
- Visibility: public
- $arg string - <p>Argument</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::args($arg)
Adds arguments
- Visibility: public
- $arg mixed
\PhilWaters\Process\Process PhilWaters\Process\Process::async()
Configures the process to run asynchronously. The run method will return a waiter instead of the output.
- Visibility: public
\PhilWaters\Process\Process PhilWaters\Process\Process::log(string $path, \PhilWaters\Process\number $mode)
Sets the path to a log file
- Visibility: public
- $path string - <p>Log file path</p>
- $mode PhilWaters\Process\number - <p>Log write mode (FILE_APPEND)</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::stdin(mixed $stdin, string $type)
Sets STDIN source (file or pipe)
- Visibility: public
- $stdin mixed - <p>File path or value to pass to STDIN</p>
- $type string - <p>file or pipe</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::stdout(string $path, string $mode)
Sets STDOUT path
- Visibility: public
- $path string - <p>File path</p>
- $mode string - <p>Write mode (FILE_APPEND)</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::stderr(string $path, string $mode)
Sets STDERR path
- Visibility: public
- $path string - <p>File path</p>
- $mode string - <p>Write mode (FILE_APPEND)</p>
\PhilWaters\Process\Process PhilWaters\Process\Process::env(array $env)
Sets array of environment variables
- Visibility: public
- $env array - <p>Array of environment variables</p>
\PhilWaters\Process\Waiter|array PhilWaters\Process\Process::run()
Runs the command
- Visibility: public
string PhilWaters\Process\Process::buildCommand()
Builds command string
- Visibility: public
boolean PhilWaters\Process\Waiter::wait(\PhilWaters\Process\number $timeout)
Wait for the process to finish
- Visibility: public
- $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>
void PhilWaters\Process\Waiter::terminate(integer $signal)
Terminates process
- Visibility: public
- $signal integer - <p>Kill signal</p>