Interface
ProcessInterface
A child process started with Process::run(), with its standard streams usable from coroutines.
Introduction#
read() and write() wait for their stream without blocking the other coroutines. When the process has ended and isRunning() or another status call has noticed it, its streams are closed, so read the output before asking.
Class synopsis#
interface ProcessInterface {
/* Methods */
public ProcessInterface::stop(): bool
public ProcessInterface::isRunning(): bool
public ProcessInterface::isStopped(): bool
public ProcessInterface::getExitCode(): int|false
public ProcessInterface::sendSignal(int $signal = 15): bool
public ProcessInterface::read(int $fd = self::STDOUT): string|false
public ProcessInterface::write(string $data, int $fd = self::STDIN): int|false
public ProcessInterface::getStream(int $fd): mixed
}Constants#
| Name | Value | Description |
|---|---|---|
STDIN | 0 | |
STDOUT | 1 | |
STDERR | 2 |
Methods#
| Method | Description |
|---|---|
stop | Ends the process: SIGTERM, then SIGKILL after one second, and waits up to five seconds in all. |
isRunning | Returns true if the process is running. |
isStopped | Returns true if the process is paused by a stop signal. |
getExitCode | Returns the exit code of the process, or false while it runs. |
sendSignal | Sends a signal to the process, and returns false without sending it if the process is not running. |
read | Waits until the stream has something to read, and returns what is there. |
write | Waits until the stream can take data, and writes as much as it takes. |
getStream | Returns the stream of a standard descriptor, for stream_select(), phasync::readable() and the like. |
Examples#
phasync::run(function () {
$cat = phasync\Util\Process::run('cat');
$cat->write("ping\n");
echo $cat->read(); // ping
$cat->stop();
});See also#
Process::runStarts$commandin the background and returns the object that controls it.