Symfony2 API
Class

Symfony\Component\Process\PhpProcess

class PhpProcess extends Process

PhpProcess runs a PHP script in an independent process.

$p = new PhpProcess('<?php echo "foo"; ?>');
$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($line)

from Process
addErrorOutput($line)

from Process
getCommandLine()

from Process
setCommandLine($commandline)

from Process
getTimeout()

from Process
setTimeout($timeout)

from Process
getWorkingDirectory()

from Process
setWorkingDirectory($cwd)

from Process
getEnv()

from Process
setEnv(array $env)

from Process
getStdin()

from Process
setStdin($stdin)

from Process
getOptions()

from Process
setOptions(array $options)

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

Exceptions

RuntimeException When proc_open is not installed

at line 67
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

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

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

in Process at line 222
public integer getExitCode()

Returns the exit code returned by the process.

Return Value

integer The exit status code

in Process at line 234
public Boolean isSuccessful()

Checks if the process ended successfully.

Return Value

Boolean true if the process ended successfully, false otherwise

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

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

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

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

in Process at line 295
public addOutput($line)

Parameters

$line

in Process at line 300
public addErrorOutput($line)

Parameters

$line

in Process at line 305
public getCommandLine()

in Process at line 310
public setCommandLine($commandline)

Parameters

$commandline

in Process at line 315
public getTimeout()

in Process at line 320
public setTimeout($timeout)

Parameters

$timeout

in Process at line 325
public getWorkingDirectory()

in Process at line 330
public setWorkingDirectory($cwd)

Parameters

$cwd

in Process at line 335
public getEnv()

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

Parameters

array $env

in Process at line 345
public getStdin()

in Process at line 350
public setStdin($stdin)

Parameters

$stdin

in Process at line 355
public getOptions()

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

Parameters

array $options

at line 52
public setPhpBinary($php)

Sets the path to the PHP binary to use.

Parameters

$php