PhpProcess runs a PHP script in an independent process.
$p = new PhpProcess('<?php echo "foo"; ?>');
$p->run();
print $p->getOutput()."\n";
- author Fabien Potencier
- Extends
- Implements
IteratorAggregate Traversable
Constants |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
public Symfony |
Properties |
public static Symfony\Component\Process\Process::$exitCodes = ['OK', 'General error', 'Misuse of shell builtins', 126 => 'Invoked command cannot execute', 127 => 'Command not found', 128 => 'Invalid exit argument', 129 => 'Hangup', 130 => 'Interrupt', 131 => 'Quit and dump core', 132 => 'Illegal instruction', 133 => 'Trace/breakpoint trap', 134 => 'Process aborted', 135 => 'Bus error: "access to undefined portion of memory object"', 136 => 'Floating point exception: "erroneous arithmetic operation"', 137 => 'Kill (terminate immediately)', 138 => 'User-defined 1', 139 => 'Segmentation violation', 140 => 'User-defined 2', 141 => 'Write to pipe with no one reading', 142 => 'Signal raised by alarm', 143 => 'Termination (request to terminate)', 145 => 'Child process terminated, stopped (or continued*)', 146 => 'Continue if stopped', 147 => 'Stop executing temporarily', 148 => 'Terminal stop signal', 149 => 'Background process attempting to read from tty ("in")', 150 => 'Background process attempting to write to tty ("out")', 151 => 'Urgent data available on socket', 152 => 'CPU time limit exceeded', 153 => 'File size limit exceeded', 154 => 'Signal raised by timer counting virtual time: "virtual timer expired"', 155 => 'Profiling timer expired', 157 => 'Pollable event', 159 => 'Bad syscall'] Exit codes translation table. User-defined errors must use exit codes in the 64-113 range. |
Methods |
public Symfony\Component\Process\Process::__clone() |
public __construct(string $script, ?string $cwd = NULL, ?array $env = NULL, int $timeout = 60, ?array $php = NULL)
|
public Symfony\Component\Process\Process::__destruct() |
public Symfony\Component\Process\Process::__sleep() : array |
public Symfony\Component\Process\Process::__wakeup() |
public Symfony\Component\Process\Process::addErrorOutput(string $line) : void Adds a line to the STDERR stream.
|
public Symfony\Component\Process\Process::addOutput(string $line) : void Adds a line to the STDOUT stream.
|
public 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
|
public Symfony\Component\Process\Process::clearErrorOutput() : static Clears the process output.
|
public Symfony\Component\Process\Process::clearOutput() : static Clears the process output.
|
public Symfony\Component\Process\Process::disableOutput() : static Disables fetching output and error output from the underlying process.
|
public Symfony\Component\Process\Process::enableOutput() : static Enables fetching output and error output from the underlying process.
|
public static fromShellCommandline(string $command, ?string $cwd = NULL, ?array $env = NULL, ?mixed $input = NULL, ?float $timeout = 60) : static |
public Symfony\Component\Process\Process::getCommandLine() : string Gets the command line to be executed. |
public Symfony\Component\Process\Process::getEnv() : array Gets the environment variables. |
public Symfony\Component\Process\Process::getErrorOutput() : string Returns the current error output of the process (STDERR).
|
public Symfony\Component\Process\Process::getExitCode() : ?int Returns the exit code returned by the process.
|
public Symfony\Component\Process\Process::getExitCodeText() : ?string Returns a string representation for the exit code returned by the process. This method relies on the Unix exit code status standardization
|
public Symfony\Component\Process\Process::getIdleTimeout() : ?float Gets the process idle timeout in seconds (max. time since last output). |
public Symfony\Component\Process\Process::getIncrementalErrorOutput() : string Returns the errorOutput incrementally. In comparison with the getErrorOutput method which always return the
|
public Symfony\Component\Process\Process::getIncrementalOutput() : string Returns the output incrementally. In comparison with the getOutput method which always return the whole
|
public Symfony\Component\Process\Process::getInput() Gets the Process input.
|
public Symfony\Component\Process\Process::getIterator(int $flags = 0) : Generator Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
|
public Symfony\Component\Process\Process::getLastOutputTime() : ?float Gets the last output time in seconds. |
public Symfony\Component\Process\Process::getOutput() : string Returns the current output of the process (STDOUT).
|
public Symfony\Component\Process\Process::getPid() : ?int Returns the Pid (process identifier), if applicable.
|
public Symfony\Component\Process\Process::getStartTime() : float
|
public Symfony\Component\Process\Process::getStatus() : string Gets the process status. The status is one of: ready, started, terminated. |
public Symfony\Component\Process\Process::getStopSignal() : int Returns the number of the signal that caused the child process to stop its execution. It is only meaningful if hasBeenStopped() returns true.
|
public Symfony\Component\Process\Process::getTermSignal() : int Returns the number of the signal that caused the child process to terminate its execution. It is only meaningful if hasBeenSignaled() returns true.
|
public Symfony\Component\Process\Process::getTimeout() : ?float Gets the process timeout in seconds (max. runtime). |
public Symfony\Component\Process\Process::getWorkingDirectory() : ?string Gets the working directory. |
public Symfony\Component\Process\Process::hasBeenSignaled() : bool Returns true if the child process has been terminated by an uncaught signal. It always returns false on Windows.
|
public Symfony\Component\Process\Process::hasBeenStopped() : bool Returns true if the child process has been stopped by a signal. It always returns false on Windows.
|
public Symfony\Component\Process\Process::isOutputDisabled() : bool Returns true in case the output is disabled, false otherwise. |
public Symfony\Component\Process\Process::isPty() : bool Returns PTY state. |
public static Symfony\Component\Process\Process::isPtySupported() : bool Returns whether PTY is supported on the current operating system. |
public Symfony\Component\Process\Process::isRunning() : bool Checks if the process is currently running. |
public Symfony\Component\Process\Process::isStarted() : bool Checks if the process has been started with no regard to the current state. |
public Symfony\Component\Process\Process::isSuccessful() : bool Checks if the process ended successfully. |
public Symfony\Component\Process\Process::isTerminated() : bool Checks if the process is terminated. |
public Symfony\Component\Process\Process::isTty() : bool Checks if the TTY mode is enabled. |
public static Symfony\Component\Process\Process::isTtySupported() : bool Returns whether TTY is supported on the current operating system. |
public Symfony\Component\Process\Process::mustRun(?callable $callback = NULL, array $env = []) : static Runs the process. This is identical to run() except that an exception is thrown if the process
|
public Symfony\Component\Process\Process::restart(?callable $callback = NULL, array $env = []) : static Restarts the process. Be warned that the process is cloned before being started.
|
public Symfony\Component\Process\Process::run(?callable $callback = NULL, array $env = []) : int Runs the process. The callback receives the type of output (out or err) and The STDOUT and STDERR are also available after the process is finished
|
public Symfony\Component\Process\Process::setEnv(array $env) : static Sets the environment variables.
|
public Symfony\Component\Process\Process::setIdleTimeout(?float $timeout) : static Sets the process idle timeout (max. time since last output) in seconds. To disable the timeout, set this value to null.
|
public Symfony\Component\Process\Process::setInput(?mixed $input) : static Sets the input. This content will be passed to the underlying process standard input.
|
public Symfony\Component\Process\Process::setOptions(array $options) Defines options to pass to the underlying proc_open().
|
public Symfony\Component\Process\Process::setPty(bool $bool) : static Sets PTY mode.
|
public Symfony\Component\Process\Process::setTimeout(?float $timeout) : static Sets the process timeout (max. runtime) in seconds. To disable the timeout, set this value to null.
|
public Symfony\Component\Process\Process::setTty(bool $tty) : static Enables or disables the TTY mode.
|
public Symfony\Component\Process\Process::setWorkingDirectory(string $cwd) : static Sets the current working directory.
|
public Symfony\Component\Process\Process::signal(int $signal) : static Sends a POSIX signal to the process.
|
public start(?callable $callback = NULL, array $env = [])
|
public Symfony\Component\Process\Process::stop(float $timeout = 10, ?int $signal = NULL) : ?int Stops the process.
|
public Symfony\Component\Process\Process::wait(?callable $callback = NULL) : int Waits for the process to terminate. The callback receives the type of output (out or err) and some bytes
|
public Symfony\Component\Process\Process::waitUntil(callable $callback) : bool Waits until the callback returns true. The callback receives the type of output (out or err) and some bytes
|
Methods |
protected Symfony\Component\Process\Process::buildCallback(?callable $callback = NULL) : Closure Builds up the callback used by wait(). The callbacks adds all occurred output to the specific buffer and calls
|
protected Symfony\Component\Process\Process::isSigchildEnabled() : bool Returns whether PHP has been compiled with the '--enable-sigchild' option or not. |
protected Symfony\Component\Process\Process::updateStatus(bool $blocking) Updates the status of the process, reads pipes.
|
Properties |
public static Symfony\Component\Process\Process::$exitCodes = ['OK', 'General error', 'Misuse of shell builtins', 126 => 'Invoked command cannot execute', 127 => 'Command not found', 128 => 'Invalid exit argument', 129 => 'Hangup', 130 => 'Interrupt', 131 => 'Quit and dump core', 132 => 'Illegal instruction', 133 => 'Trace/breakpoint trap', 134 => 'Process aborted', 135 => 'Bus error: "access to undefined portion of memory object"', 136 => 'Floating point exception: "erroneous arithmetic operation"', 137 => 'Kill (terminate immediately)', 138 => 'User-defined 1', 139 => 'Segmentation violation', 140 => 'User-defined 2', 141 => 'Write to pipe with no one reading', 142 => 'Signal raised by alarm', 143 => 'Termination (request to terminate)', 145 => 'Child process terminated, stopped (or continued*)', 146 => 'Continue if stopped', 147 => 'Stop executing temporarily', 148 => 'Terminal stop signal', 149 => 'Background process attempting to read from tty ("in")', 150 => 'Background process attempting to write to tty ("out")', 151 => 'Urgent data available on socket', 152 => 'CPU time limit exceeded', 153 => 'File size limit exceeded', 154 => 'Signal raised by timer counting virtual time: "virtual timer expired"', 155 => 'Profiling timer expired', 157 => 'Pollable event', 159 => 'Bad syscall'] Exit codes translation table. User-defined errors must use exit codes in the 64-113 range. |
Methods |
public static fromShellCommandline(string $command, ?string $cwd = NULL, ?array $env = NULL, ?mixed $input = NULL, ?float $timeout = 60) : static |
public static Symfony\Component\Process\Process::isPtySupported() : bool Returns whether PTY is supported on the current operating system. |
public static Symfony\Component\Process\Process::isTtySupported() : bool Returns whether TTY is supported on the current operating system. |