Symfony2 API
Class

Symfony\Component\Process\Process

class Process

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

Methods

__construct(string $commandline, string $cwd = null, array $env = null, string $stdin = null, integer $timeout = 60, array $options = array())

Constructor.

integer run(Closure|string|array $callback = null)

Runs the process.

string getOutput()

Returns the output of the process (STDOUT).

string getErrorOutput()

Returns the error output of the process (STDERR).

integer getExitCode()

Returns the exit code returned by the process.

Boolean isSuccessful()

Checks if the process ended successfully.

Boolean hasBeenSignaled()

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

integer getTermSignal()

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

Boolean hasBeenStopped()

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

integer getStopSignal()

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

addOutput($line)

addErrorOutput($line)

getCommandLine()

setCommandLine($commandline)

getTimeout()

setTimeout($timeout)

getWorkingDirectory()

setWorkingDirectory($cwd)

getEnv()

setEnv(array $env)

getStdin()

setStdin($stdin)

getOptions()

setOptions(array $options)

Details

at line 49
public __construct(string $commandline, string $cwd = null, array $env = null, string $stdin = null, integer $timeout = 60, array $options = array())

Constructor.

Parameters

string $commandline The command line to run
string $cwd The working directory
array $env The environment variables
string $stdin The STDIN content
integer $timeout The timeout in seconds
array $options An array of options for proc_open

Exceptions

RuntimeException When proc_open is not installed

at line 89
public integer run(Closure|string|array $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

Closure|string|array $callback A PHP callback to run whenever there is some output available on STDOUT or STDERR

Return Value

integer The exit status code

Exceptions

RuntimeException When process can't be launch or is stopped

at line 195
public string getOutput()

Returns the output of the process (STDOUT).

This only returns the output if you have not supplied a callback
to the run() method.

Return Value

string The process output

at line 210
public string getErrorOutput()

Returns the error output of the process (STDERR).

This only returns the error output if you have not supplied a callback
to the run() method.

Return Value

string The process error output

at line 222
public integer getExitCode()

Returns the exit code returned by the process.

Return Value

integer The exit status code

at line 234
public Boolean isSuccessful()

Checks if the process ended successfully.

Return Value

Boolean true if the process ended successfully, false otherwise

at line 248
public Boolean hasBeenSignaled()

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

It always returns false on Windows.

Return Value

Boolean

at line 262
public integer getTermSignal()

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

It is only meaningful if hasBeenSignaled() returns true.

Return Value

integer

at line 276
public Boolean hasBeenStopped()

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

It always returns false on Windows.

Return Value

Boolean

at line 290
public integer getStopSignal()

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

It is only meaningful if hasBeenStopped() returns true.

Return Value

integer

at line 295
public addOutput($line)

Parameters

$line

at line 300
public addErrorOutput($line)

Parameters

$line

at line 305
public getCommandLine()

at line 310
public setCommandLine($commandline)

Parameters

$commandline

at line 315
public getTimeout()

at line 320
public setTimeout($timeout)

Parameters

$timeout

at line 325
public getWorkingDirectory()

at line 330
public setWorkingDirectory($cwd)

Parameters

$cwd

at line 335
public getEnv()

at line 340
public setEnv(array $env)

Parameters

array $env

at line 345
public getStdin()

at line 350
public setStdin($stdin)

Parameters

$stdin

at line 355
public getOptions()

at line 360
public setOptions(array $options)

Parameters

array $options