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(string $line)

Adds a line to the STDOUT stream.

addErrorOutput(string $line)

Adds a line to the STDERR stream.

string getCommandLine()

Gets the command line to be executed.

setCommandLine(string $commandline)

Sets the command line to be executed.

integer getTimeout()

Gets the process timeout.

setTimeout(integer|null $timeout)

Sets the process timeout.

string getWorkingDirectory()

Gets the working directory.

setWorkingDirectory(string $cwd)

Sets the current working directory.

array getEnv()

Gets the environment variables.

setEnv(array $env)

Sets the environment variables.

string getStdin()

Gets the contents of STDIN.

setStdin(string $stdin)

Sets the contents of STDIN.

array getOptions()

Gets the options for proc_open.

setOptions(array $options)

Sets the options for proc_open.

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 93
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 199
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 214
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 226
public integer getExitCode()

Returns the exit code returned by the process.

Return Value

integer The exit status code

at line 238
public Boolean isSuccessful()

Checks if the process ended successfully.

Return Value

Boolean true if the process ended successfully, false otherwise

at line 252
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 266
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 280
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 294
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 304
public addOutput(string $line)

Adds a line to the STDOUT stream.

Parameters

string $line The line to append

at line 314
public addErrorOutput(string $line)

Adds a line to the STDERR stream.

Parameters

string $line The line to append

at line 324
public string getCommandLine()

Gets the command line to be executed.

Return Value

string The command to execute

at line 334
public setCommandLine(string $commandline)

Sets the command line to be executed.

Parameters

string $commandline The command to execute

at line 344
public integer getTimeout()

Gets the process timeout.

Return Value

integer The timeout in seconds

at line 354
public setTimeout(integer|null $timeout)

Sets the process timeout.

Parameters

integer|null $timeout The timeout in seconds

at line 364
public string getWorkingDirectory()

Gets the working directory.

Return Value

string The current working directory

at line 381
public setWorkingDirectory(string $cwd)

Sets the current working directory.

Parameters

string $cwd The new working directory

at line 391
public array getEnv()

Gets the environment variables.

Return Value

array The current environment variables

at line 401
public setEnv(array $env)

Sets the environment variables.

Parameters

array $env The new environment variables

at line 411
public string getStdin()

Gets the contents of STDIN.

Return Value

string The current contents

at line 421
public setStdin(string $stdin)

Sets the contents of STDIN.

Parameters

string $stdin The new contents

at line 431
public array getOptions()

Gets the options for proc_open.

Return Value

array The current options

at line 441
public setOptions(array $options)

Sets the options for proc_open.

Parameters

array $options The new options