PhpProcess runs a PHP script in an independent process.

$p = new PhpProcess('<?php echo "foo"; ?>');
$p->run();
print $p->getOutput()."\n";

CloneableInstantiableIterable
ExtendsSymfony\Component\Process\Process
ImplementsIteratorAggregate
Traversable
Constants
public Symfony\Component\Process\Process::ERR = 'err'
public Symfony\Component\Process\Process::ITER_KEEP_OUTPUT = 2
public Symfony\Component\Process\Process::ITER_NON_BLOCKING = 1
public Symfony\Component\Process\Process::ITER_SKIP_ERR = 8
public Symfony\Component\Process\Process::ITER_SKIP_OUT = 4
public Symfony\Component\Process\Process::OUT = 'out'
public Symfony\Component\Process\Process::STATUS_READY = 'ready'
public Symfony\Component\Process\Process::STATUS_STARTED = 'started'
public Symfony\Component\Process\Process::STATUS_TERMINATED = 'terminated'
public Symfony\Component\Process\Process::STDERR = 2
public Symfony\Component\Process\Process::STDIN = 0
public Symfony\Component\Process\Process::STDOUT = 1
public Symfony\Component\Process\Process::TIMEOUT_PRECISION = 0.2
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::addErrorOutput(string $line)
     

    Adds a line to the STDERR stream.

    • internal
    public Symfony\Component\Process\Process::addOutput(string $line)
     

    Adds a line to the STDOUT stream.

    • internal
    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
    trigger this method regularly to ensure the process timeout

    • throws ProcessTimedOutException In case the timeout was reached
    public Symfony\Component\Process\Process::clearErrorOutput()
     

    Clears the process output.

    • return $this
    public Symfony\Component\Process\Process::clearOutput()
     

    Clears the process output.

    • return $this
    public Symfony\Component\Process\Process::disableOutput()
     

    Disables fetching output and error output from the underlying process.

    • return $this
    • throws RuntimeException In case the process is already running
    • throws LogicException if an idle timeout is set
    public Symfony\Component\Process\Process::enableOutput()
     

    Enables fetching output and error output from the underlying process.

    • return $this
    • throws RuntimeException In case the process is already running
    public static fromShellCommandline(string $command, ?string $cwd = NULL, ?array $env = NULL, $input = NULL, ?float $timeout = 60)
     

    {@inheritdoc}

    public Symfony\Component\Process\Process::getCommandLine()
     

    Gets the command line to be executed.

    • return string The command to execute
    public Symfony\Component\Process\Process::getEnv()
     

    Gets the environment variables.

    • return array The current environment variables
    public Symfony\Component\Process\Process::getErrorOutput()
     

    Returns the current error output of the process (STDERR).

    • return string The process error output
    • throws LogicException in case the output has been disabled
    • throws LogicException In case the process is not started
    public Symfony\Component\Process\Process::getExitCode()
     

    Returns the exit code returned by the process.

    • return int|null The exit status code, null if the Process is not terminated
    public Symfony\Component\Process\Process::getExitCodeText()
     

    Returns a string representation for the exit code returned by the process.

    This method relies on the Unix exit code status standardization
    and might not be relevant for other operating systems.

    • return string|null A string representation for the exit status code, null if the Process is not terminated
    • see http://tldp.org/LDP/abs/html/exitcodes.html
    • see http://en.wikipedia.org/wiki/Unix_signal
    public Symfony\Component\Process\Process::getIdleTimeout()
     

    Gets the process idle timeout (max. time since last output).

    • return float|null The timeout in seconds or null if it's disabled
    public Symfony\Component\Process\Process::getIncrementalErrorOutput()
     

    Returns the errorOutput incrementally.

    In comparison with the getErrorOutput method which always return the
    whole error output, this one returns the new error output since the last
    call.

    • return string The process error output since the last call
    • throws LogicException in case the output has been disabled
    • throws LogicException In case the process is not started
    public Symfony\Component\Process\Process::getIncrementalOutput()
     

    Returns the output incrementally.

    In comparison with the getOutput method which always return the whole
    output, this one returns the new output since the last call.

    • return string The process output since the last call
    • throws LogicException in case the output has been disabled
    • throws LogicException In case the process is not started
    public Symfony\Component\Process\Process::getInput()
     

    Gets the Process input.

    • return resource|string|Iterator|null The Process input
    public Symfony\Component\Process\Process::getIterator(int $flags = 0)
     

    Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).

    • throws LogicException in case the output has been disabled
    • throws LogicException In case the process is not started
    • return Generator
    public Symfony\Component\Process\Process::getLastOutputTime() : float
     

    Gets the last output time in seconds.

    • return float|null The last output time in seconds or null if it isn't started
    public Symfony\Component\Process\Process::getOutput()
     

    Returns the current output of the process (STDOUT).

    • return string The process output
    • throws LogicException in case the output has been disabled
    • throws LogicException In case the process is not started
    public Symfony\Component\Process\Process::getPid()
     

    Returns the Pid (process identifier), if applicable.

    • return int|null The process id if running, null otherwise
    public Symfony\Component\Process\Process::getStartTime() : float
     
    • throws LogicException in case process is not started
    public Symfony\Component\Process\Process::getStatus()
     

    Gets the process status.

    The status is one of: ready, started, terminated.

    • return string The current process status
    public Symfony\Component\Process\Process::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 int
    • throws LogicException In case the process is not terminated
    public Symfony\Component\Process\Process::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 int
    • throws RuntimeException In case --enable-sigchild is activated
    • throws LogicException In case the process is not terminated
    public Symfony\Component\Process\Process::getTimeout()
     

    Gets the process timeout (max. runtime).

    • return float|null The timeout in seconds or null if it's disabled
    public Symfony\Component\Process\Process::getWorkingDirectory()
     

    Gets the working directory.

    • return string|null The current working directory or null on failure
    public Symfony\Component\Process\Process::hasBeenSignaled()
     

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

    It always returns false on Windows.

    • return bool
    • throws LogicException In case the process is not terminated
    public Symfony\Component\Process\Process::hasBeenStopped()
     

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

    It always returns false on Windows.

    • return bool
    • throws LogicException In case the process is not terminated
    public Symfony\Component\Process\Process::isOutputDisabled()
     

    Returns true in case the output is disabled, false otherwise.

    • return bool
    public Symfony\Component\Process\Process::isPty()
     

    Returns PTY state.

    • return bool
    public static Symfony\Component\Process\Process::isPtySupported()
     

    Returns whether PTY is supported on the current operating system.

    • return bool
    public Symfony\Component\Process\Process::isRunning()
     

    Checks if the process is currently running.

    • return bool true if the process is currently running, false otherwise
    public Symfony\Component\Process\Process::isStarted()
     

    Checks if the process has been started with no regard to the current state.

    • return bool true if status is ready, false otherwise
    public Symfony\Component\Process\Process::isSuccessful()
     

    Checks if the process ended successfully.

    • return bool true if the process ended successfully, false otherwise
    public Symfony\Component\Process\Process::isTerminated()
     

    Checks if the process is terminated.

    • return bool true if process is terminated, false otherwise
    public Symfony\Component\Process\Process::isTty()
     

    Checks if the TTY mode is enabled.

    • return bool true if the TTY mode is enabled, false otherwise
    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 = []) : self
     

    Runs the process.

    This is identical to run() except that an exception is thrown if the process
    exits with a non-zero exit code.

    • return $this
    • throws ProcessFailedException if the process didn't terminate successfully
    • final
    public Symfony\Component\Process\Process::restart(?callable $callback = NULL, array $env = []) : self
     

    Restarts the process.

    Be warned that the process is cloned before being started.

    • return static
    • throws RuntimeException When process can't be launched
    • throws RuntimeException When process is already running
    • see \start()
    • final
    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
    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.

    • return int The exit status code
    • throws RuntimeException When process can't be launched
    • throws RuntimeException When process is already running
    • throws ProcessTimedOutException When process timed out
    • throws ProcessSignaledException When process stopped after receiving signal
    • throws LogicException In case a callback is provided and output has been disabled
    • final
    public Symfony\Component\Process\Process::setEnv(array $env)
     

    Sets the environment variables.

    Each environment variable value should be a string.
    If it is an array, the variable is ignored.
    If it is false or null, it will be removed when
    env vars are otherwise inherited.

    That happens in PHP when 'argv' is registered into
    the $_ENV array for instance.

    • return $this
    public Symfony\Component\Process\Process::setIdleTimeout(?float $timeout)
     

    Sets the process idle timeout (max. time since last output) in seconds.

    To disable the timeout, set this value to null.

    • return $this
    • throws LogicException if the output is disabled
    • throws InvalidArgumentException if the timeout is negative
    public Symfony\Component\Process\Process::setInput( $input)
     

    Sets the input.

    This content will be passed to the underlying process standard input.

    • return $this
    • throws LogicException In case the process is running
    public Symfony\Component\Process\Process::setPty(bool $bool)
     

    Sets PTY mode.

    • return $this
    public Symfony\Component\Process\Process::setTimeout(?float $timeout)
     

    Sets the process timeout (max. runtime) in seconds.

    To disable the timeout, set this value to null.

    • return $this
    • throws InvalidArgumentException if the timeout is negative
    public Symfony\Component\Process\Process::setTty(bool $tty)
     

    Enables or disables the TTY mode.

    • return $this
    • throws RuntimeException In case the TTY mode is not supported
    public Symfony\Component\Process\Process::setWorkingDirectory(string $cwd)
     

    Sets the current working directory.

    • return $this
    public Symfony\Component\Process\Process::signal(int $signal)
     

    Sends a POSIX signal to the process.

    • return $this
    • throws LogicException In case the process is not running
    • throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
    • throws RuntimeException In case of failure
    public start(?callable $callback = NULL, array $env = [])
     

    {@inheritdoc}

    public Symfony\Component\Process\Process::stop(float $timeout = 10, ?int $signal = NULL)
     

    Stops the process.

    • return int|null The exit-code of the process or null if it's not running
    public Symfony\Component\Process\Process::wait(?callable $callback = NULL)
     

    Waits for the process to terminate.

    The callback receives the type of output (out or err) and some bytes
    from the output in real-time while writing the standard input to the process.
    It allows to have feedback from the independent process during execution.

    • return int The exitcode of the process
    • throws ProcessTimedOutException When process timed out
    • throws ProcessSignaledException When process stopped after receiving signal
    • throws LogicException When process is not yet started
    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
    from the output in real-time while writing the standard input to the process.
    It allows to have feedback from the independent process during execution.

    • throws RuntimeException When process timed out
    • throws LogicException When process is not yet started
    • throws ProcessTimedOutException In case the timeout was reached
    Methods
    protected Symfony\Component\Process\Process::buildCallback(?callable $callback = NULL)
     

    Builds up the callback used by wait().

    The callbacks adds all occurred output to the specific buffer and calls
    the user callback (if present) with the received output.

    • return Closure A PHP closure
    protected Symfony\Component\Process\Process::isSigchildEnabled()
     

    Returns whether PHP has been compiled with the '--enable-sigchild' option or not.

    • return bool
    protected Symfony\Component\Process\Process::updateStatus(bool $blocking)
     

    Updates the status of the process, reads pipes.

      Methods
      private Symfony\Component\Process\Process::close() : int
       

      Closes process resource, closes file handles, sets the exitcode.

      • return int The exitcode
      private Symfony\Component\Process\Process::doSignal(int $signal, bool $throwException) : bool
       

      Sends a POSIX signal to the process.

      • return bool True if the signal was sent successfully, false otherwise
      • throws LogicException In case the process is not running
      • throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
      • throws RuntimeException In case of failure
      private Symfony\Component\Process\Process::escapeArgument(?string $argument) : string
       

      Escapes a string to be used as a shell argument.

      private Symfony\Component\Process\Process::getDefaultEnv() : array
      private Symfony\Component\Process\Process::getDescriptors() : array
       

      Creates the descriptors needed by the proc_open.

      private Symfony\Component\Process\Process::prepareWindowsCommandLine(string $cmd, array $env) : string
      private Symfony\Component\Process\Process::readPipes(bool $blocking, bool $close)
       

      Reads pipes, executes callback.

        private Symfony\Component\Process\Process::readPipesForOutput(string $caller, bool $blocking = false)
         

        Reads pipes for the freshest output.

        • throws LogicException in case output has been disabled or process is not started
        private Symfony\Component\Process\Process::replacePlaceholders(string $commandline, array $env)
        private Symfony\Component\Process\Process::requireProcessIsStarted(string $functionName)
         

        Ensures the process is running or terminated, throws a LogicException if the process has a not started.

        • throws LogicException if the process has not run
        private Symfony\Component\Process\Process::requireProcessIsTerminated(string $functionName)
         

        Ensures the process is terminated, throws a LogicException if the process has a status different than "terminated".

        • throws LogicException if the process is not yet terminated
        private Symfony\Component\Process\Process::resetProcessData()
         

        Resets data related to the latest run of the process.

        private Symfony\Component\Process\Process::validateTimeout(?float $timeout) : float
         

        Validates and returns the filtered timeout.

        • throws InvalidArgumentException if the given timeout is a negative number
        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, $input = NULL, ?float $timeout = 60)
         

        {@inheritdoc}

        public static Symfony\Component\Process\Process::isPtySupported()
         

        Returns whether PTY is supported on the current operating system.

        • return bool
        public static Symfony\Component\Process\Process::isTtySupported() : bool
         

        Returns whether TTY is supported on the current operating system.

        © 2020 Bruce Wells
        Search Namespaces \ Classes
        ConfigurationNumbers (0-9.) only