PHP 클래스 Symfony\Component\Process\Process

저자: Fabien Potencier ([email protected])
파일 보기 프로젝트 열기: symfony/process 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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.

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.

getEnhanceWindowsCompatibility() 공개 메소드

This is true by default.

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