Class

Symfony\Component\Process\PhpProcess

class PhpProcess extends Process

PhpProcess runs a PHP script in an independent process.

$p = new PhpProcess(''); $p->run(); print $p->getOutput()."\n";

Methods

__construct(string $script, string $cwd = null, array $env = array(), 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).

from Process
string getErrorOutput()

Returns the error output of the process (STDERR).

from Process
integer getExitCode()

Returns the exit code returned by the process.

from Process
Boolean isSuccessful()

Checks if the process ended successfully.

from Process
Boolean hasBeenSignaled()

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

from Process
integer getTermSignal()

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

from Process
Boolean hasBeenStopped()

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

from Process
integer getStopSignal()

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

from Process
addOutput(string $line)

Adds a line to the STDOUT stream.

from Process
addErrorOutput(string $line)

Adds a line to the STDERR stream.

from Process
string getCommandLine()

Gets the command line to be executed.

from Process
setCommandLine(string $commandline)

Sets the command line to be executed.

from Process
integer getTimeout()

Gets the process timeout.

from Process
setTimeout(integer|null $timeout)

Sets the process timeout.

from Process
string getWorkingDirectory()

Gets the working directory.

from Process
setWorkingDirectory(string $cwd)

Sets the current working directory.

from Process
array getEnv()

Gets the environment variables.

from Process
setEnv(array $env)

Sets the environment variables.

from Process
string getStdin()

Gets the contents of STDIN.

from Process
setStdin(string $stdin)

Sets the contents of STDIN.

from Process
array getOptions()

Gets the options for proc_open.

from Process
setOptions(array $options)

Sets the options for proc_open.

from Process
setPhpBinary($php)

Sets the path to the PHP binary to use.

Details

at line 40
public __construct(string $script, string $cwd = null, array $env = array(), integer $timeout = 60, array $options = array())

Constructor.

Parameters

string $script The PHP script to run (as a string)
string $cwd The working directory
array $env The environment variables
integer $timeout The timeout in seconds
array $options An array of options for proc_open

at line 67
public integer run(Closure|string|array $callback = null)

Runs the process.

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

in Process 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

in Process 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

in Process at line 226
public integer getExitCode()

Returns the exit code returned by the process.

Return Value

integer The exit status code

in Process at line 238
public Boolean isSuccessful()

Checks if the process ended successfully.

Return Value

Boolean true if the process ended successfully, false otherwise

in Process 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

in Process 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

in Process 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

in Process 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

in Process at line 304
public addOutput(string $line)

Adds a line to the STDOUT stream.

Parameters

string $line The line to append

in Process at line 314
public addErrorOutput(string $line)

Adds a line to the STDERR stream.

Parameters

string $line The line to append

in Process at line 324
public string getCommandLine()

Gets the command line to be executed.

Return Value

string The command to execute

in Process at line 334
public setCommandLine(string $commandline)

Sets the command line to be executed.

Parameters

string $commandline The command to execute

in Process at line 344
public integer getTimeout()

Gets the process timeout.

Return Value

integer The timeout in seconds

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

Sets the process timeout.

Parameters

integer|null $timeout The timeout in seconds

in Process at line 364
public string getWorkingDirectory()

Gets the working directory.

Return Value

string The current working directory

in Process at line 381
public setWorkingDirectory(string $cwd)

Sets the current working directory.

Parameters

string $cwd The new working directory

in Process at line 391
public array getEnv()

Gets the environment variables.

Return Value

array The current environment variables

in Process at line 401
public setEnv(array $env)

Sets the environment variables.

Parameters

array $env The new environment variables

in Process at line 411
public string getStdin()

Gets the contents of STDIN.

Return Value

string The current contents

in Process at line 421
public setStdin(string $stdin)

Sets the contents of STDIN.

Parameters

string $stdin The new contents

in Process at line 431
public array getOptions()

Gets the options for proc_open.

Return Value

array The current options

in Process at line 441
public setOptions(array $options)

Sets the options for proc_open.

Parameters

array $options The new options

at line 52
public setPhpBinary($php)

Sets the path to the PHP binary to use.

Parameters

$php