phil-waters / process
Allows command line commands to be run asynchronously
0.4.0
2017-04-21 23:11 UTC
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-11-15 21:08:33 UTC
README
Process allows command line commands to be run asynchronously.
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
- Visibility: public
Arguments
- $cwd string - <p>Working directory</p>
cmd
\PhilWaters\Process\Process PhilWaters\Process\Process::cmd(string $cmd)
Sets the command to run
- Visibility: public
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
- Visibility: public
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
- Visibility: public
Arguments
- $arg string - <p>Argument</p>
args
\PhilWaters\Process\Process PhilWaters\Process\Process::args($arg)
Adds arguments
- Visibility: public
Arguments
- $arg mixed
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.
- Visibility: public
log
\PhilWaters\Process\Process PhilWaters\Process\Process::log(string $path, \PhilWaters\Process\number $mode)
Sets the path to a log file
- Visibility: public
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)
- Visibility: public
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
- Visibility: public
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
- Visibility: public
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
- Visibility: public
Arguments
- $env array - <p>Array of environment variables</p>
run
\PhilWaters\Process\Waiter|array PhilWaters\Process\Process::run()
Runs the command
- Visibility: public
buildCommand
string PhilWaters\Process\Process::buildCommand()
Builds command string
- Visibility: public
Waiter Methods
wait
boolean PhilWaters\Process\Waiter::wait(\PhilWaters\Process\number $timeout)
Wait for the process to finish
- Visibility: public
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
- Visibility: public
Arguments
- $signal integer - <p>Kill signal</p>