PHP Класс Symfony\Component\Process\Process

Автор: Fabien Potencier ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$exitCodes array User-defined errors must use exit codes in the 64-113 range.

Открытые методы

Метод Описание
__clone ( )
__construct ( string $commandline, string | null $cwd = null, array $env = null, mixed | null $input = null, integer | float | null $timeout = 60, array $options = [] ) Constructor.
__destruct ( )
addErrorOutput ( string $line ) Adds a line to the STDERR stream.
addOutput ( string $line ) Adds a line to the STDOUT stream.
areEnvironmentVariablesInherited ( ) : boolean Returns whether environment variables will be inherited or not.
checkTimeout ( ) Performs a check between the timeout definition and the time the process started.
clearErrorOutput ( ) : Process Clears the process output.
clearOutput ( ) : Process Clears the process output.
disableOutput ( ) : Process Disables fetching output and error output from the underlying process.
enableOutput ( ) : Process Enables fetching output and error output from the underlying process.
getCommandLine ( ) : string Gets the command line to be executed.
getEnhanceSigchildCompatibility ( ) : boolean Returns whether sigchild compatibility mode is activated or not.
getEnhanceWindowsCompatibility ( ) : boolean Gets whether or not Windows compatibility is enabled.
getEnv ( ) : array Gets the environment variables.
getErrorOutput ( ) : string Returns the current error output of the process (STDERR).
getExitCode ( ) : null | integer Returns the exit code returned by the process.
getExitCodeText ( ) : null | string Returns a string representation for the exit code returned by the process.
getIdleTimeout ( ) : float | null Gets the process idle timeout (max. time since last output).
getIncrementalErrorOutput ( ) : string Returns the errorOutput incrementally.
getIncrementalOutput ( ) : string Returns the output incrementally.
getInput ( ) : resource | string | Iterator | null Gets the Process input.
getIterator ( integer $flags ) : Generator Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
getOptions ( ) : array Gets the options for proc_open.
getOutput ( ) : string Returns the current output of the process (STDOUT).
getPid ( ) : integer | null Returns the Pid (process identifier), if applicable.
getStatus ( ) : string Gets the process status.
getStopSignal ( ) : integer Returns the number of the signal that caused the child process to stop its execution.
getTermSignal ( ) : integer Returns the number of the signal that caused the child process to terminate its execution.
getTimeout ( ) : float | null Gets the process timeout (max. runtime).
getWorkingDirectory ( ) : string | null Gets the working directory.
hasBeenSignaled ( ) : boolean Returns true if the child process has been terminated by an uncaught signal.
hasBeenStopped ( ) : boolean Returns true if the child process has been stopped by a signal.
inheritEnvironmentVariables ( boolean $inheritEnv = true ) : self Sets whether environment variables will be inherited or not.
isOutputDisabled ( ) : boolean Returns true in case the output is disabled, false otherwise.
isPty ( ) : boolean Returns PTY state.
isPtySupported ( ) : boolean Returns whether PTY is supported on the current operating system.
isRunning ( ) : boolean Checks if the process is currently running.
isStarted ( ) : boolean Checks if the process has been started with no regard to the current state.
isSuccessful ( ) : boolean Checks if the process ended successfully.
isTerminated ( ) : boolean Checks if the process is terminated.
isTty ( ) : boolean Checks if the TTY mode is enabled.
mustRun ( callable $callback = null ) : self Runs the process.
restart ( callable $callback = null ) : Process Restarts the process.
run ( callable | null $callback = null ) : integer Runs the process.
setCommandLine ( string $commandline ) : self Sets the command line to be executed.
setEnhanceSigchildCompatibility ( boolean $enhance ) : self Activates sigchild compatibility mode.
setEnhanceWindowsCompatibility ( boolean $enhance ) : self Sets whether or not Windows compatibility is enabled.
setEnv ( array $env ) : self Sets the environment variables.
setIdleTimeout ( integer | float | null $timeout ) : self Sets the process idle timeout (max. time since last output).
setInput ( resource | scalar | Traversable | null $input ) : self Sets the input.
setOptions ( array $options ) : self Sets the options for proc_open.
setPty ( boolean $bool ) : self Sets PTY mode.
setTimeout ( integer | float | null $timeout ) : self Sets the process timeout (max. runtime).
setTty ( boolean $tty ) : self Enables or disables the TTY mode.
setWorkingDirectory ( string $cwd ) : self Sets the current working directory.
signal ( integer $signal ) : Process Sends a POSIX signal to the process.
start ( callable $callback = null ) Starts the process and returns after writing the input to STDIN.
stop ( integer | float $timeout = 10, integer $signal = null ) : integer Stops the process.
wait ( callable $callback = null ) : integer Waits for the process to terminate.

Защищенные методы

Метод Описание
buildCallback ( callable $callback = null ) : Closure Builds up the callback used by wait().
isSigchildEnabled ( ) : boolean Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
updateStatus ( boolean $blocking ) Updates the status of the process, reads pipes.

Приватные методы

Метод Описание
close ( ) : integer Closes process resource, closes file handles, sets the exitcode.
doSignal ( integer $signal, boolean $throwException ) : boolean Sends a POSIX signal to the process.
getDescriptors ( ) : array Creates the descriptors needed by the proc_open.
readPipes ( boolean $blocking, boolean $close ) Reads pipes, executes callback.
readPipesForOutput ( string $caller, boolean $blocking = false ) Reads pipes for the freshest output.
requireProcessIsStarted ( string $functionName ) Ensures the process is running or terminated, throws a LogicException if the process has a not started.
requireProcessIsTerminated ( string $functionName ) Ensures the process is terminated, throws a LogicException if the process has a status different than terminated.
resetProcessData ( ) Resets data related to the latest run of the process.
validateTimeout ( integer | float | null $timeout ) : float | null Validates and returns the filtered timeout.

Описание методов

__clone() публичный Метод

public __clone ( )

__construct() публичный Метод

Constructor.
public __construct ( string $commandline, string | null $cwd = null, array $env = null, mixed | null $input = null, integer | float | null $timeout = 60, array $options = [] )
$commandline string The command line to run
$cwd string | null The working directory or null to use the working dir of the current PHP process
$env array The environment variables or null to use the same environment as the current PHP process
$input mixed | null The input as stream resource, scalar or \Traversable, or null for no input
$timeout integer | float | null The timeout in seconds or null to disable
$options array An array of options for proc_open

__destruct() публичный Метод

public __destruct ( )

addErrorOutput() публичный Метод

Adds a line to the STDERR stream.
public addErrorOutput ( string $line )
$line string The line to append

addOutput() публичный Метод

Adds a line to the STDOUT stream.
public addOutput ( string $line )
$line string The line to append

areEnvironmentVariablesInherited() публичный Метод

Returns whether environment variables will be inherited or not.
public areEnvironmentVariablesInherited ( ) : boolean
Результат boolean

buildCallback() защищенный Метод

The callbacks adds all occurred output to the specific buffer and calls the user callback (if present) with the received output.
protected buildCallback ( callable $callback = null ) : Closure
$callback callable The user defined PHP callback
Результат Closure A PHP closure

checkTimeout() публичный Метод

In case you run a background process (with the start method), you should trigger this method regularly to ensure the process timeout
public checkTimeout ( )

clearErrorOutput() публичный Метод

Clears the process output.
public clearErrorOutput ( ) : Process
Результат Process

clearOutput() публичный Метод

Clears the process output.
public clearOutput ( ) : Process
Результат Process

disableOutput() публичный Метод

Disables fetching output and error output from the underlying process.
public disableOutput ( ) : Process
Результат Process

enableOutput() публичный Метод

Enables fetching output and error output from the underlying process.
public enableOutput ( ) : Process
Результат Process

getCommandLine() публичный Метод

Gets the command line to be executed.
public getCommandLine ( ) : string
Результат string The command to execute

getEnhanceSigchildCompatibility() публичный Метод

Returns whether sigchild compatibility mode is activated or not.
public getEnhanceSigchildCompatibility ( ) : boolean
Результат boolean

getEnhanceWindowsCompatibility() публичный Метод

This is true by default.
public getEnhanceWindowsCompatibility ( ) : boolean
Результат boolean

getEnv() публичный Метод

Gets the environment variables.
public getEnv ( ) : array
Результат array The current environment variables

getErrorOutput() публичный Метод

Returns the current error output of the process (STDERR).
public getErrorOutput ( ) : string
Результат string The process error output

getExitCode() публичный Метод

Returns the exit code returned by the process.
public getExitCode ( ) : null | integer
Результат null | integer The exit status code, null if the Process is not terminated

getExitCodeText() публичный Метод

This method relies on the Unix exit code status standardization and might not be relevant for other operating systems.
См. также: http://tldp.org/LDP/abs/html/exitcodes.html
См. также: http://en.wikipedia.org/wiki/Unix_signal
public getExitCodeText ( ) : null | string
Результат null | string A string representation for the exit status code, null if the Process is not terminated

getIdleTimeout() публичный Метод

Gets the process idle timeout (max. time since last output).
public getIdleTimeout ( ) : float | null
Результат float | null The timeout in seconds or null if it's disabled

getIncrementalErrorOutput() публичный Метод

In comparison with the getErrorOutput method which always return the whole error output, this one returns the new error output since the last call.
public getIncrementalErrorOutput ( ) : string
Результат string The process error output since the last call

getIncrementalOutput() публичный Метод

In comparison with the getOutput method which always return the whole output, this one returns the new output since the last call.
public getIncrementalOutput ( ) : string
Результат string The process output since the last call

getInput() публичный Метод

Gets the Process input.
public getInput ( ) : resource | string | Iterator | null
Результат resource | string | Iterator | null The Process input

getIterator() публичный Метод

Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
public getIterator ( integer $flags ) : Generator
$flags integer A bit field of Process::ITER_* flags
Результат Generator

getOptions() публичный Метод

Gets the options for proc_open.
public getOptions ( ) : array
Результат array The current options

getOutput() публичный Метод

Returns the current output of the process (STDOUT).
public getOutput ( ) : string
Результат string The process output

getPid() публичный Метод

Returns the Pid (process identifier), if applicable.
public getPid ( ) : integer | null
Результат integer | null The process id if running, null otherwise

getStatus() публичный Метод

The status is one of: ready, started, terminated.
public getStatus ( ) : string
Результат string The current process status

getStopSignal() публичный Метод

It is only meaningful if hasBeenStopped() returns true.
public getStopSignal ( ) : integer
Результат integer

getTermSignal() публичный Метод

It is only meaningful if hasBeenSignaled() returns true.
public getTermSignal ( ) : integer
Результат integer

getTimeout() публичный Метод

Gets the process timeout (max. runtime).
public getTimeout ( ) : float | null
Результат float | null The timeout in seconds or null if it's disabled

getWorkingDirectory() публичный Метод

Gets the working directory.
public getWorkingDirectory ( ) : string | null
Результат string | null The current working directory or null on failure

hasBeenSignaled() публичный Метод

It always returns false on Windows.
public hasBeenSignaled ( ) : boolean
Результат boolean

hasBeenStopped() публичный Метод

It always returns false on Windows.
public hasBeenStopped ( ) : boolean
Результат boolean

inheritEnvironmentVariables() публичный Метод

Sets whether environment variables will be inherited or not.
public inheritEnvironmentVariables ( boolean $inheritEnv = true ) : self
$inheritEnv boolean
Результат self The current Process instance

isOutputDisabled() публичный Метод

Returns true in case the output is disabled, false otherwise.
public isOutputDisabled ( ) : boolean
Результат boolean

isPty() публичный Метод

Returns PTY state.
public isPty ( ) : boolean
Результат boolean

isPtySupported() публичный статический Метод

Returns whether PTY is supported on the current operating system.
public static isPtySupported ( ) : boolean
Результат boolean

isRunning() публичный Метод

Checks if the process is currently running.
public isRunning ( ) : boolean
Результат boolean true if the process is currently running, false otherwise

isSigchildEnabled() защищенный Метод

Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
protected isSigchildEnabled ( ) : boolean
Результат boolean

isStarted() публичный Метод

Checks if the process has been started with no regard to the current state.
public isStarted ( ) : boolean
Результат boolean true if status is ready, false otherwise

isSuccessful() публичный Метод

Checks if the process ended successfully.
public isSuccessful ( ) : boolean
Результат boolean true if the process ended successfully, false otherwise

isTerminated() публичный Метод

Checks if the process is terminated.
public isTerminated ( ) : boolean
Результат boolean true if process is terminated, false otherwise

isTty() публичный Метод

Checks if the TTY mode is enabled.
public isTty ( ) : boolean
Результат boolean true if the TTY mode is enabled, false otherwise

mustRun() публичный Метод

This is identical to run() except that an exception is thrown if the process exits with a non-zero exit code.
public mustRun ( callable $callback = null ) : self
$callback callable
Результат self

restart() публичный Метод

Be warned that the process is cloned before being started.
См. также: start()
public restart ( callable $callback = null ) : Process
$callback callable A PHP callback to run whenever there is some output available on STDOUT or STDERR
Результат Process The new process

run() публичный Метод

The callback receives the type of output (out or err) and some bytes from the output in real-time. It allows to have feedback from the independent process during execution. The STDOUT and STDERR are also available after the process is finished via the getOutput() and getErrorOutput() methods.
public run ( callable | null $callback = null ) : integer
$callback callable | null A PHP callback to run whenever there is some output available on STDOUT or STDERR
Результат integer The exit status code

setCommandLine() публичный Метод

Sets the command line to be executed.
public setCommandLine ( string $commandline ) : self
$commandline string The command to execute
Результат self The current Process instance

setEnhanceSigchildCompatibility() публичный Метод

Sigchild compatibility mode is required to get the exit code and determine the success of a process when PHP has been compiled with the --enable-sigchild option
public setEnhanceSigchildCompatibility ( boolean $enhance ) : self
$enhance boolean
Результат self The current Process instance

setEnhanceWindowsCompatibility() публичный Метод

Sets whether or not Windows compatibility is enabled.
public setEnhanceWindowsCompatibility ( boolean $enhance ) : self
$enhance boolean
Результат self The current Process instance

setEnv() публичный Метод

An environment variable value should be a string. If it is an array, the variable is ignored. That happens in PHP when 'argv' is registered into the $_ENV array for instance.
public setEnv ( array $env ) : self
$env array The new environment variables
Результат self The current Process instance

setIdleTimeout() публичный Метод

To disable the timeout, set this value to null.
public setIdleTimeout ( integer | float | null $timeout ) : self
$timeout integer | float | null The timeout in seconds
Результат self The current Process instance

setInput() публичный Метод

This content will be passed to the underlying process standard input.
public setInput ( resource | scalar | Traversable | null $input ) : self
$input resource | scalar | Traversable | null The content
Результат self The current Process instance

setOptions() публичный Метод

Sets the options for proc_open.
public setOptions ( array $options ) : self
$options array The new options
Результат self The current Process instance

setPty() публичный Метод

Sets PTY mode.
public setPty ( boolean $bool ) : self
$bool boolean
Результат self

setTimeout() публичный Метод

To disable the timeout, set this value to null.
public setTimeout ( integer | float | null $timeout ) : self
$timeout integer | float | null The timeout in seconds
Результат self The current Process instance

setTty() публичный Метод

Enables or disables the TTY mode.
public setTty ( boolean $tty ) : self
$tty boolean True to enabled and false to disable
Результат self The current Process instance

setWorkingDirectory() публичный Метод

Sets the current working directory.
public setWorkingDirectory ( string $cwd ) : self
$cwd string The new working directory
Результат self The current Process instance

signal() публичный Метод

Sends a POSIX signal to the process.
public signal ( integer $signal ) : Process
$signal integer A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
Результат Process

start() публичный Метод

This method blocks until all STDIN data is sent to the process then it returns while the process runs in the background. The termination of the process can be awaited with wait(). The callback receives the type of output (out or err) and some bytes from the output in real-time while writing the standard input to the process. It allows to have feedback from the independent process during execution.
public start ( callable $callback = null )
$callback callable A PHP callback to run whenever there is some output available on STDOUT or STDERR

stop() публичный Метод

Stops the process.
public stop ( integer | float $timeout = 10, integer $signal = null ) : integer
$timeout integer | float The timeout in seconds
$signal integer A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
Результат integer The exit-code of the process

updateStatus() защищенный Метод

Updates the status of the process, reads pipes.
protected updateStatus ( boolean $blocking )
$blocking boolean Whether to use a blocking read call

wait() публичный Метод

The callback receives the type of output (out or err) and some bytes from the output in real-time while writing the standard input to the process. It allows to have feedback from the independent process during execution.
public wait ( callable $callback = null ) : integer
$callback callable A valid PHP callback
Результат integer The exitcode of the process

Описание свойств

$exitCodes публичное статическое свойство

User-defined errors must use exit codes in the 64-113 range.
public static array $exitCodes
Результат array