BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
Symfony\Component\Process\Process Class Reference
Inheritance diagram for Symfony\Component\Process\Process:
Collaboration diagram for Symfony\Component\Process\Process:

Public Member Functions

 __construct ($commandline, $cwd=null, array $env=null, $input=null, $timeout=60, array $options=null)
 
 __clone ()
 
 run ($callback=null)
 
 mustRun (callable $callback=null)
 
 start (callable $callback=null)
 
 restart (callable $callback=null)
 
 wait (callable $callback=null)
 
 getPid ()
 
 signal ($signal)
 
 disableOutput ()
 
 enableOutput ()
 
 isOutputDisabled ()
 
 getOutput ()
 
 getIncrementalOutput ()
 
 getIterator ($flags=0)
 
 clearOutput ()
 
 getErrorOutput ()
 
 getIncrementalErrorOutput ()
 
 clearErrorOutput ()
 
 getExitCode ()
 
 getExitCodeText ()
 
 isSuccessful ()
 
 hasBeenSignaled ()
 
 getTermSignal ()
 
 hasBeenStopped ()
 
 getStopSignal ()
 
 isRunning ()
 
 isStarted ()
 
 isTerminated ()
 
 getStatus ()
 
 stop ($timeout=10, $signal=null)
 
 addOutput ($line)
 
 addErrorOutput ($line)
 
 getCommandLine ()
 
 setCommandLine ($commandline)
 
 getTimeout ()
 
 getIdleTimeout ()
 
 setTimeout ($timeout)
 
 setIdleTimeout ($timeout)
 
 setTty ($tty)
 
 isTty ()
 
 setPty ($bool)
 
 isPty ()
 
 getWorkingDirectory ()
 
 setWorkingDirectory ($cwd)
 
 getEnv ()
 
 setEnv (array $env)
 
 getInput ()
 
 setInput ($input)
 
 getOptions ()
 
 setOptions (array $options)
 
 getEnhanceWindowsCompatibility ()
 
 setEnhanceWindowsCompatibility ($enhance)
 
 getEnhanceSigchildCompatibility ()
 
 setEnhanceSigchildCompatibility ($enhance)
 
 inheritEnvironmentVariables ($inheritEnv=true)
 
 areEnvironmentVariablesInherited ()
 
 checkTimeout ()
 

Static Public Member Functions

static isPtySupported ()
 

Public Attributes

const ERR = 'err'
 
const OUT = 'out'
 
const STATUS_READY = 'ready'
 
const STATUS_STARTED = 'started'
 
const STATUS_TERMINATED = 'terminated'
 
const STDIN = 0
 
const STDOUT = 1
 
const STDERR = 2
 
const TIMEOUT_PRECISION = 0.2
 
const ITER_NON_BLOCKING = 1
 
const ITER_KEEP_OUTPUT = 2
 
const ITER_SKIP_OUT = 4
 
const ITER_SKIP_ERR = 8
 

Static Public Attributes

static $exitCodes
 

Protected Member Functions

 buildCallback (callable $callback=null)
 
 updateStatus ($blocking)
 
 isSigchildEnabled ()
 

Detailed Description

Process is a thin wrapper around proc_* functions to easily start independent PHP processes.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com
Romain Neutron impre.nosp@m.c@gm.nosp@m.ail.c.nosp@m.om

Constructor & Destructor Documentation

Symfony\Component\Process\Process::__construct (   $commandline,
  $cwd = null,
array  $env = null,
  $input = null,
  $timeout = 60,
array  $options = null 
)
Parameters
string | array$commandlineThe command line to run
string | null$cwdThe working directory or null to use the working dir of the current PHP process
array | null$envThe environment variables or null to use the same environment as the current PHP process
mixed | null$inputThe input as stream resource, scalar or , or null for no input
int | float | null$timeoutThe timeout in seconds or null to disable
array$optionsAn array of options for proc_open
Exceptions
RuntimeExceptionWhen proc_open is not installed

Member Function Documentation

Symfony\Component\Process\Process::addErrorOutput (   $line)

Adds a line to the STDERR stream.

Symfony\Component\Process\Process::addOutput (   $line)

Adds a line to the STDOUT stream.

Symfony\Component\Process\Process::areEnvironmentVariablesInherited ( )

Returns whether environment variables will be inherited or not.

Returns
bool
Deprecated:
since version 3.3, to be removed in 4.0. Environment variables will always be inherited.
Symfony\Component\Process\Process::buildCallback ( callable  $callback = null)
protected

Builds up the callback used by wait().

The callbacks adds all occurred output to the specific buffer and calls the user callback (if present) with the received output.

Parameters
callable | null$callbackThe user defined PHP callback
Returns
A PHP closure
Symfony\Component\Process\Process::checkTimeout ( )

Performs a check between the timeout definition and the time the process started.

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

Exceptions
ProcessTimedOutExceptionIn case the timeout was reached
Symfony\Component\Process\Process::clearErrorOutput ( )

Clears the process output.

Returns
$this
Symfony\Component\Process\Process::clearOutput ( )

Clears the process output.

Returns
$this
Symfony\Component\Process\Process::disableOutput ( )

Disables fetching output and error output from the underlying process.

Returns
$this
Exceptions
RuntimeExceptionIn case the process is already running
LogicExceptionif an idle timeout is set
Symfony\Component\Process\Process::enableOutput ( )

Enables fetching output and error output from the underlying process.

Returns
$this
Exceptions
RuntimeExceptionIn case the process is already running
Symfony\Component\Process\Process::getCommandLine ( )

Gets the command line to be executed.

Returns
string The command to execute
Symfony\Component\Process\Process::getEnhanceSigchildCompatibility ( )

Returns whether sigchild compatibility mode is activated or not.

Returns
bool
Deprecated:
since version 3.3, to be removed in 4.0. Sigchild compatibility will always be enabled.
Symfony\Component\Process\Process::getEnhanceWindowsCompatibility ( )

Gets whether or not Windows compatibility is enabled.

This is true by default.

Returns
bool
Deprecated:
since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
Symfony\Component\Process\Process::getEnv ( )

Gets the environment variables.

Returns
array The current environment variables
Symfony\Component\Process\Process::getErrorOutput ( )

Returns the current error output of the process (STDERR).

Returns
string The process error output
Exceptions
LogicExceptionin case the output has been disabled
LogicExceptionIn case the process is not started
Symfony\Component\Process\Process::getExitCode ( )

Returns the exit code returned by the process.

Returns
null|int The exit status code, null if the Process is not terminated
Exceptions
RuntimeExceptionIn case –enable-sigchild is activated and the sigchild compatibility mode is disabled
Symfony\Component\Process\Process::getExitCodeText ( )

Returns a string representation for the exit code returned by the process.

This method relies on the Unix exit code status standardization and might not be relevant for other operating systems.

Returns
null|string A string representation for the exit status code, null if the Process is not terminated
See Also
http://tldp.org/LDP/abs/html/exitcodes.html
http://en.wikipedia.org/wiki/Unix_signal
Symfony\Component\Process\Process::getIdleTimeout ( )

Gets the process idle timeout (max. time since last output).

Returns
float|null The timeout in seconds or null if it's disabled
Symfony\Component\Process\Process::getIncrementalErrorOutput ( )

Returns the errorOutput incrementally.

In comparison with the getErrorOutput method which always return the whole error output, this one returns the new error output since the last call.

Returns
string The process error output since the last call
Exceptions
LogicExceptionin case the output has been disabled
LogicExceptionIn case the process is not started
Symfony\Component\Process\Process::getIncrementalOutput ( )

Returns the output incrementally.

In comparison with the getOutput method which always return the whole output, this one returns the new output since the last call.

Returns
string The process output since the last call
Exceptions
LogicExceptionin case the output has been disabled
LogicExceptionIn case the process is not started
Symfony\Component\Process\Process::getInput ( )

Gets the Process input.

Returns
resource|string||null The Process input
Symfony\Component\Process\Process::getIterator (   $flags = 0)

Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).

Parameters
int$flagsA bit field of Process::ITER_* flags
Exceptions
LogicExceptionin case the output has been disabled
LogicExceptionIn case the process is not started
Returns
Symfony\Component\Process\Process::getOptions ( )

Gets the options for proc_open.

Returns
array The current options
Deprecated:
since version 3.3, to be removed in 4.0.
Symfony\Component\Process\Process::getOutput ( )

Returns the current output of the process (STDOUT).

Returns
string The process output
Exceptions
LogicExceptionin case the output has been disabled
LogicExceptionIn case the process is not started
Symfony\Component\Process\Process::getPid ( )

Returns the Pid (process identifier), if applicable.

Returns
int|null The process id if running, null otherwise
Symfony\Component\Process\Process::getStatus ( )

Gets the process status.

The status is one of: ready, started, terminated.

Returns
string The current process status
Symfony\Component\Process\Process::getStopSignal ( )

Returns the number of the signal that caused the child process to stop its execution.

It is only meaningful if hasBeenStopped() returns true.

Returns
int
Exceptions
LogicExceptionIn case the process is not terminated
Symfony\Component\Process\Process::getTermSignal ( )

Returns the number of the signal that caused the child process to terminate its execution.

It is only meaningful if hasBeenSignaled() returns true.

Returns
int
Exceptions
RuntimeExceptionIn case –enable-sigchild is activated
LogicExceptionIn case the process is not terminated
Symfony\Component\Process\Process::getTimeout ( )

Gets the process timeout (max. runtime).

Returns
float|null The timeout in seconds or null if it's disabled
Symfony\Component\Process\Process::getWorkingDirectory ( )

Gets the working directory.

Returns
string|null The current working directory or null on failure
Symfony\Component\Process\Process::hasBeenSignaled ( )

Returns true if the child process has been terminated by an uncaught signal.

It always returns false on Windows.

Returns
bool
Exceptions
RuntimeExceptionIn case –enable-sigchild is activated
LogicExceptionIn case the process is not terminated
Symfony\Component\Process\Process::hasBeenStopped ( )

Returns true if the child process has been stopped by a signal.

It always returns false on Windows.

Returns
bool
Exceptions
LogicExceptionIn case the process is not terminated
Symfony\Component\Process\Process::inheritEnvironmentVariables (   $inheritEnv = true)

Sets whether environment variables will be inherited or not.

Parameters
bool$inheritEnv
Returns
self The current Process instance
Symfony\Component\Process\Process::isOutputDisabled ( )

Returns true in case the output is disabled, false otherwise.

Returns
bool
Symfony\Component\Process\Process::isPty ( )

Returns PTY state.

Returns
bool
static Symfony\Component\Process\Process::isPtySupported ( )
static

Returns whether PTY is supported on the current operating system.

Returns
bool
Symfony\Component\Process\Process::isRunning ( )

Checks if the process is currently running.

Returns
bool true if the process is currently running, false otherwise
Symfony\Component\Process\Process::isSigchildEnabled ( )
protected

Returns whether PHP has been compiled with the '–enable-sigchild' option or not.

Returns
bool
Symfony\Component\Process\Process::isStarted ( )

Checks if the process has been started with no regard to the current state.

Returns
bool true if status is ready, false otherwise
Symfony\Component\Process\Process::isSuccessful ( )

Checks if the process ended successfully.

Returns
bool true if the process ended successfully, false otherwise
Symfony\Component\Process\Process::isTerminated ( )

Checks if the process is terminated.

Returns
bool true if process is terminated, false otherwise
Symfony\Component\Process\Process::isTty ( )

Checks if the TTY mode is enabled.

Returns
bool true if the TTY mode is enabled, false otherwise
Symfony\Component\Process\Process::mustRun ( callable  $callback = null)

Runs the process.

This is identical to run() except that an exception is thrown if the process exits with a non-zero exit code.

Parameters
callable | null$callback
array$envAn array of additional env vars to set when running the process
Returns
self
Exceptions
RuntimeExceptionif PHP was compiled with –enable-sigchild and the enhanced sigchild compatibility mode is not enabled
ProcessFailedExceptionif the process didn't terminate successfully

since version 3.3

Symfony\Component\Process\Process::restart ( callable  $callback = null)

Restarts the process.

Be warned that the process is cloned before being started.

Parameters
callable | null$callbackA PHP callback to run whenever there is some output available on STDOUT or STDERR
array$envAn array of additional env vars to set when running the process
Returns
$this
Exceptions
RuntimeExceptionWhen process can't be launched
RuntimeExceptionWhen process is already running
See Also
start()

since version 3.3

Symfony\Component\Process\Process::run (   $callback = null)

Runs the process.

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.

Parameters
callable | null$callbackA PHP callback to run whenever there is some output available on STDOUT or STDERR
array$envAn array of additional env vars to set when running the process
Returns
int The exit status code
Exceptions
RuntimeExceptionWhen process can't be launched
RuntimeExceptionWhen process stopped after receiving signal
LogicExceptionIn case a callback is provided and output has been disabled

since version 3.3

Symfony\Component\Process\Process::setCommandLine (   $commandline)

Sets the command line to be executed.

Parameters
string | array$commandlineThe command to execute
Returns
self The current Process instance
Symfony\Component\Process\Process::setEnhanceSigchildCompatibility (   $enhance)

Activates sigchild compatibility mode.

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

Parameters
bool$enhance
Returns
self The current Process instance
Deprecated:
since version 3.3, to be removed in 4.0.
Symfony\Component\Process\Process::setEnhanceWindowsCompatibility (   $enhance)

Sets whether or not Windows compatibility is enabled.

Parameters
bool$enhance
Returns
self The current Process instance
Deprecated:
since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
Symfony\Component\Process\Process::setEnv ( array  $env)

Sets the environment variables.

An environment variable value should be a string. If it is an array, the variable is ignored. If it is false or null, it will be removed when env vars are otherwise inherited.

That happens in PHP when 'argv' is registered into the $_ENV array for instance.

Parameters
array$envThe new environment variables
Returns
self The current Process instance
Symfony\Component\Process\Process::setIdleTimeout (   $timeout)

Sets the process idle timeout (max. time since last output).

To disable the timeout, set this value to null.

Parameters
int | float | null$timeoutThe timeout in seconds
Returns
self The current Process instance
Exceptions
LogicExceptionif the output is disabled
InvalidArgumentExceptionif the timeout is negative
Symfony\Component\Process\Process::setInput (   $input)

Sets the input.

This content will be passed to the underlying process standard input.

Parameters
resource | scalar | \Traversable | null$inputThe content
Returns
self The current Process instance
Exceptions
LogicExceptionIn case the process is running
Symfony\Component\Process\Process::setOptions ( array  $options)

Sets the options for proc_open.

Parameters
array$optionsThe new options
Returns
self The current Process instance
Deprecated:
since version 3.3, to be removed in 4.0.
Symfony\Component\Process\Process::setPty (   $bool)

Sets PTY mode.

Parameters
bool$bool
Returns
self
Symfony\Component\Process\Process::setTimeout (   $timeout)

Sets the process timeout (max. runtime).

To disable the timeout, set this value to null.

Parameters
int | float | null$timeoutThe timeout in seconds
Returns
self The current Process instance
Exceptions
InvalidArgumentExceptionif the timeout is negative
Symfony\Component\Process\Process::setTty (   $tty)

Enables or disables the TTY mode.

Parameters
bool$ttyTrue to enabled and false to disable
Returns
self The current Process instance
Exceptions
RuntimeExceptionIn case the TTY mode is not supported
Symfony\Component\Process\Process::setWorkingDirectory (   $cwd)

Sets the current working directory.

Parameters
string$cwdThe new working directory
Returns
self The current Process instance
Symfony\Component\Process\Process::signal (   $signal)

Sends a POSIX signal to the process.

Parameters
int$signalA valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
Returns
$this
Exceptions
LogicExceptionIn case the process is not running
RuntimeExceptionIn case –enable-sigchild is activated and the process can't be killed
RuntimeExceptionIn case of failure
Symfony\Component\Process\Process::start ( callable  $callback = null)

Starts the process and returns after writing the input to STDIN.

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.

Parameters
callable | null$callbackA PHP callback to run whenever there is some output available on STDOUT or STDERR
array$envAn array of additional env vars to set when running the process
Exceptions
RuntimeExceptionWhen process can't be launched
RuntimeExceptionWhen process is already running
LogicExceptionIn case a callback is provided and output has been disabled
Symfony\Component\Process\Process::stop (   $timeout = 10,
  $signal = null 
)

Stops the process.

Parameters
int | float$timeoutThe timeout in seconds
int$signalA POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
Returns
int The exit-code of the process
Symfony\Component\Process\Process::updateStatus (   $blocking)
protected

Updates the status of the process, reads pipes.

Parameters
bool$blockingWhether to use a blocking read call
Symfony\Component\Process\Process::wait ( callable  $callback = null)

Waits for the process to terminate.

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.

Parameters
callable | null$callbackA valid PHP callback
Returns
int The exitcode of the process
Exceptions
RuntimeExceptionWhen process timed out
RuntimeExceptionWhen process stopped after receiving signal
LogicExceptionWhen process is not yet started

Member Data Documentation

Symfony\Component\Process\Process::$exitCodes
static

Exit codes translation table.

User-defined errors must use exit codes in the 64-113 range.


The documentation for this class was generated from the following file: