Process
MMO\core\server · 1 symbol · generated 5 Oct 2026
Process
Process.php:34Process is a thin wrapper around proc_* functions to easily start independent PHP processes.
- Namespace
MMO\core\server- Implements
- IteratorAggregate, Stringable
- Uses traits
- tPropertyGetter
- Author
- Fabien Potencier <fabien@symfony.com>, Romain Neutron <imprec@gmail.com>, Marc Mouret <marc@hydra-agency.com>
Index
| ITER_KEEP_OUTPUT | ||
| ITER_NON_BLOCKING | ||
| ITER_SKIP_ERR | ||
| ITER_SKIP_OUT | ||
| STATUS_READY | ||
| STATUS_STARTED | ||
| STATUS_TERMINATED | ||
| STDERR | ||
| STDOUT | ||
| callback | ||
| command | ||
| cwd | ||
| env | ||
| exitcode | ||
| fallbackStatus | ||
| idleTimeout | ||
| incrementalErrorOutputOffset | ||
| incrementalOutputOffset | ||
| info | ||
| input | ||
| lastOutputTime | ||
| latestSignal | ||
| outputDisabled | ||
| process | ||
| processPipes | ||
| pty | ||
| starttime | ||
| status | ||
| stderr | ||
| stdout | ||
| timeout | ||
| tty | ||
| addOutput($line, $type) | Adds a line to the STDOUT stream. | |
| buildCallback($callback) | Builds up the callback used by wait(). | |
| checkTimeout() | Performs a check between the timeout definition and the time the process started. | |
| clearOutput($type) | Clears the process output. | |
| close() | Closes process resource, closes file handles, sets the exitcode. | |
| debugName() | ||
| getExitCode() | Returns the exit code returned by the process. | |
| getIncrementalOutput($type) | Returns the output incrementally. | |
| getIterator($flags) | Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR). | |
| getOutput($type) | Returns the current output of the process (STDOUT). | |
| getPid() | Returns the Pid (process identifier), if applicable. | |
| getStatus() | Gets the process status. | |
| getStopSignal() | Returns the number of the signal that caused the child process to stop its execution. | |
| getTermSignal() | Returns the number of the signal that caused the child process to terminate its execution. | |
| hasBeenSignaled() | Returns true if the child process has been terminated by an uncaught signal. | |
| hasBeenStopped() | Returns true if the child process has been stopped by a signal. | |
| isRunning() | Checks if the process is currently running. | |
| isStarted() | Checks if the process has been started with no regard to the current state. | |
| isSuccessful() | Checks if the process ended successfully. | |
| isTerminated() | Checks if the process is terminated. | |
| logErrors($logger, $logCommand) | Log the process's stderr output, if it has any, as a warning. | |
| readPipes($blocking, $close) | Reads pipes, executes callback. | |
| readPipesForOutput($blocking) | Reads pipes for the freshest output. | |
| reset() | Resets data related to the latest run of the process. | |
| restart($callback, $env) | Restarts the process. | |
| run($callback, $env) | Runs the process. | |
| setEnv($env) | Sets the environment variables. | |
| setIdleTimeout($timeout) | Sets the process idle timeout (max. | |
| setInput($input) | Sets the input. | |
| setOutputDisabled($disable) | Disables/Enables fetching output and error output from the underlying process. | |
| setPty($pty) | Sets PTY mode. | |
| setTimeout($timeout) | Sets the process timeout (max. | |
| setTty($tty) | Enables or disables the TTY mode. | |
| setWorkingDirectory($cwd) | Sets the current working directory. | |
| signal($signal, $throwException) | Sends a POSIX signal to the process. | |
| start($callback, $env) | Starts the process and returns after writing the input to STDIN. | |
| stop($timeout, $signal) | Stops the process. | |
| updateStatus($blocking) | Updates the status of the process, reads pipes. | |
| wait($callback) | Waits for the process to terminate. | |
| waitUntil($callback) | Waits until the callback returns true. | |
| __clone() | A clone is a fresh, not-yet-started process (its own run's output/status is not carried over -- see reset). | |
| __construct($command, $cwd, $env, $input, $timeout) | ||
| __destruct() | Force-stops the process (if still running) when this object is garbage-collected, so it's never left running unattended. | |
| __get($key) | __get -- allow read access to a protected/private property from outside the class. | |
| __isset($key) | __isset | |
| __toString() |
Constants9
ITER_KEEP_OUTPUT
ITER_NON_BLOCKING
ITER_SKIP_ERR
ITER_SKIP_OUT
STATUS_READY
STATUS_STARTED
STATUS_TERMINATED
STDERR
STDOUT
Properties23
callback
command
- Type
- string
cwd
- Type
- string
env
exitcode
fallbackStatus
- Type
- array
idleTimeout
incrementalErrorOutputOffset
- Type
- int
incrementalOutputOffset
- Type
- int
info
input
- Type
- mixed
lastOutputTime
latestSignal
outputDisabled
- Type
- bool
process
processPipes
pty
- Type
- bool
starttime
status
- Type
- int
stderr
stdout
timeout
tty
- Type
- bool
Methods46
addOutput($line, $type)
Process.php:1023Adds a line to the STDOUT stream.
buildCallback($callback)
Process.php:181Builds up the callback used by wait().
checkTimeout()
Process.php:517Performs a check between the timeout definition and the time the process started.
| returns | ||
| throws | In case the timeout was reached |
clearOutput($type)
Process.php:952Clears the process output.
| $type = self::STDOUT | int | |
| returns |
close()
Process.php:232Closes process resource, closes file handles, sets the exitcode.
| returns | int | The exitcode |
debugName()
Process.php:130| returns |
getExitCode()
Process.php:772Returns the exit code returned by the process.
getIncrementalOutput($type)
Process.php:934Returns the output incrementally.
| $type = self::STDOUT | int | |
| returns | The process output since the last call | |
| throws | in case the output has been disabled | |
| throws | In case the process is not started |
getIterator($flags)
Process.php:977Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR).
| $flags = 0 | int | A bit field of Process::ITER_* flags |
| returns | Traversable | |
| throws | in case the output has been disabled | |
| throws | In case the process is not started |
getOutput($type)
Process.php:917Returns the current output of the process (STDOUT).
| $type = self::STDOUT | int | |
| returns | The process output | |
| throws | in case the output has been disabled | |
| throws | In case the process is not started |
getPid()
Process.php:903Returns the Pid (process identifier), if applicable.
| returns | The process id if running, null otherwise |
getStatus()
Process.php:763Gets the process status.
| returns | int | The current process status: one of the STATUS_* constants |
getStopSignal()
Process.php:893Returns the number of the signal that caused the child process to stop its execution.
| returns | ||
| throws | In case the process is not terminated |
getTermSignal()
Process.php:846Returns the number of the signal that caused the child process to terminate its execution.
| returns | ||
| throws | In case --enable-sigchild is activated | |
| throws | In case the process is not terminated |
hasBeenSignaled()
Process.php:865Returns true if the child process has been terminated by an uncaught signal.
| returns | ||
| throws | In case the process is not terminated |
hasBeenStopped()
Process.php:879Returns true if the child process has been stopped by a signal.
| returns | ||
| throws | In case the process is not terminated |
isRunning()
Process.php:807Checks if the process is currently running.
| returns | true if the process is currently running, false otherwise |
isStarted()
Process.php:819Checks if the process has been started with no regard to the current state.
| returns | true if status is ready, false otherwise |
isSuccessful()
Process.php:798Checks if the process ended successfully.
| returns | true if the process ended successfully, false otherwise |
isTerminated()
Process.php:828Checks if the process is terminated.
| returns | true if process is terminated, false otherwise |
logErrors($logger, $logCommand)
Process.php:140Log the process's stderr output, if it has any, as a warning.
| $logger | LoggerInterface | |
| $logCommand = true | bool | if true, append the command line itself to the logged message. |
| returns | the stderr output that was logged (empty if there was none). |
readPipes($blocking, $close)
Process.php:212Reads pipes, executes callback.
readPipesForOutput($blocking)
Process.php:199Reads pipes for the freshest output.
| $blocking = false | bool | Whether to use blocking calls or not |
| returns | ||
| throws | in case output has been disabled or process is not started |
reset()
Process.php:156Resets data related to the latest run of the process.
| returns |
restart($callback, $env)
Process.php:547Restarts the process.
- See
start()
run($callback, $env)
Process.php:419Runs the process.
| $callback = null | null | callable | A PHP callback to run whenever there is some output available on STDOUT or STDERR |
| $env = [] | array | |
| returns | int | The exit status code |
| throws | When process can't be launched | |
| throws | When process is already running | |
| throws | When process timed out | |
| throws | When process stopped after receiving signal | |
| throws | In case a callback is provided and output has been disabled |
setEnv($env)
Process.php:268Sets the environment variables.
setIdleTimeout($timeout)
Process.php:389Sets the process idle timeout (max. time since last output) in seconds.
setInput($input)
Process.php:306Sets the input.
| $input | The content | |
| returns | ||
| throws | In case the process is running | |
| throws | In case the input is not of the correct type |
setOutputDisabled($disable)
Process.php:357Disables/Enables fetching output and error output from the underlying process.
| $disable | ||
| returns | ||
| throws | In case the process is already running | |
| throws | if an idle timeout is set |
setPty($pty)
Process.php:328Sets PTY mode.
| $pty | bool | |
| returns |
setTimeout($timeout)
Process.php:373Sets the process timeout (max. runtime) in seconds.
setTty($tty)
Process.php:339Enables or disables the TTY mode.
| $tty | bool | |
| returns | ||
| throws | in case the TTY mode is not supported |
setWorkingDirectory($cwd)
Process.php:285Sets the current working directory.
signal($signal, $throwException)
Process.php:692Sends a POSIX signal to the process.
| $signal | int | A valid POSIX signal (see https://php.net/pcntl.constants) |
| $throwException = true | bool | Whether to throw exception in case signal failed |
| returns | bool | True if the signal was sent successfully, false otherwise |
| throws | In case the process is not running | |
| throws | In case --enable-sigchild is activated and the process can't be killed | |
| throws | In case of failure |
start($callback, $env)
Process.php:444Starts the process and returns after writing the input to STDIN.
stop($timeout, $signal)
Process.php:565Stops the process.
updateStatus($blocking)
Process.php:736Updates the status of the process, reads pipes.
wait($callback)
Process.php:607Waits for the process to terminate.
waitUntil($callback)
Process.php:651Waits until the callback returns true.
__clone()
Process.php:120A clone is a fresh, not-yet-started process (its own run's output/status is not carried over -- see reset).
__construct($command, $cwd, $env, $input, $timeout)
Process.php:105| $command | string | The command to run and its arguments listed as separate entries |
| $cwd = null | null | string | The working directory or null to use the working dir of the current PHP process |
| $env = null | null | array | The environment variables or null to use the same environment as the current PHP process |
| $input = null | The input as stream resource, scalar or \Traversable, or null for no input | |
| $timeout = 60.0 | null | float | The timeout in seconds or null to disable |
| throws | When proc_open is not installed |
__destruct()
Process.php:115Force-stops the process (if still running) when this object is garbage-collected, so it's never left running unattended.
__get($key)
tPropertyGetter.php:25__get -- allow read access to a protected/private property from outside the class.
| $key | ||
| returns | ||
| throws | if no such property exists at all (a declared-but-uninitialized typed property is returned as-is here, and would raise PHP's own "must not be accessed before initialization" error, not this exception) |
__isset($key)
tPropertyGetter.php:36__isset
| $key | ||
| returns |
__toString()
Process.php:125| returns | string | the raw command line. |