Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/takuya/php-process
- Owner: takuya
- License: gpl-3.0
- Created: 2020-03-13T06:59:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-19T06:09:16.000Z (over 2 years ago)
- Last Synced: 2024-10-13T18:39:21.201Z (about 1 month ago)
- Topics: php-library, php7, pipe, process, processing, shell
- Language: PHP
- Size: 167 KB
- Stars: 6
- Watchers: 3
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```phppipe('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