Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/takuya/php-process

php proc_open wrapper class for shell command process.
https://github.com/takuya/php-process

php-library php7 pipe process processing shell

Last synced: 21 days ago
JSON representation

php proc_open wrapper class for shell command process.

Awesome Lists containing this project

README

        

php-Process for proc_open
=================

The Process class component executes command in proc_open.

![](https://circleci.com/gh/takuya/php-process.svg?style=shield)

Sample
------
```php
setInput('echo HelloWorld')
->pipe('cat')
->pipe('cat')
->pipe(['grep', 'Hello'])
->wait();

$ret = stream_get_contents($fd_out);

```

[ → READ More Sample for usage ](https://github.com/takuya/php-process/blob/master/samples/README.md)

Installation
----
```sh
composer require takuya/process
```

Features
----

### Buffered IO stream for STDOUT/STDERR

Process will return buffered IO for read/write

Method will return stream.

```php

run();

$output = stream_get_contents($fd_out);
// you can reuse, re-read output
fseek($fd_out,0);
$str = stream_get_contents($fd_out);
```
### Pseudo-thread style programming
```php
start();
echo 'started';
$proc->join();
```

### Chain Method for Pipe Command

Process#pipe() can PIPE programs.

Implicite connect pipe stdout -> stdin
```php

pipe('cat')
->pipe('cat')
->pipe('cat')
->pipe('cat')
->wait();
```
Explicitly Pipe, connect (Proc1#)stdout -> (Proc2#)stdin
```php
start();
$proc2->setInput($p1_out);
$proc2->start();
$proc2->wait();
$proc1->wait();
```
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.

```php