php proc_open wrapper class for shell command process management.

1.3.6 2021-03-10 16:53 UTC

This package is auto-updated.

Last update: 2024-05-19 10:44:05 UTC


The Process class component executes command in proc_open.




$proc1 = new Process('sh');

$fd_out = $proc1->setInput('echo HelloWorld')
  ->pipe(['grep', 'Hello'])

$ret = stream_get_contents($fd_out);

→ READ More Sample for usage


composer require takuya/process


Buffered IO stream for STDOUT/STDERR

Process will return buffered IO for read/write

Method will return stream.

$proc = new Process(['echo', 'HelloWorld']);
$fd_out = $proc->run();

$output = stream_get_contents($fd_out);
// you can reuse, re-read output  
$str = stream_get_contents($fd_out);

Pseudo-thread style programming

$proc = new Process('sh sleep.sh');
echo 'started';

Chain Method for Pipe Command

Process#pipe() can PIPE programs.

Implicite connect pipe stdout -> stdin

$proc = new Process(['echo', 'HelloWorld']);
$fd_out =  $proc->pipe('cat')

Explicitly Pipe, connect (Proc1#)stdout -> (Proc2#)stdin

$proc1 = new Process(['echo', 'HelloWorld']);
$proc2 = new Process(['cat']);
[$p1_out,$p1_err] = $proc1->start();

Notice: $proc2->wait() call first, to avoid long locking , to run two process in parallel. The reason is Process class adopt implied IOBuffering at wait, so calling wait() means that runs stream buffering loop until process end.

A Simple way, Only Single File for use.

No extra packages required.

A Single File src/Process.php need to use. just write require_once like this.

require_once 'src/Process.php';

This Process class is written by vanilla php. No extra packages. No pear, No composer, No other packages need to install.
Using this without composer.phar or other Package manager, all you need is Just write require_once.

More Samples

More Usage , Read files in this procjet /samples, /tests/Features and ./docs.