定制 takuya/process 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

takuya/process

Composer 安装命令:

composer require takuya/process

包简介

php proc_open wrapper class for shell command process management.

README 文档

README

The Process class component executes command in proc_open.

NEW packages -> php-Process-exec

Caution !

I re-write this package and split into two package.

please use these class. instead of using this packages.

This package intended to be used as SINGLE-FILE not complicated composer package.

Sample

<?php

$proc1 = new Process('sh');

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

$ret = stream_get_contents($fd_out);

→ READ More Sample for usage

Installation

composer require takuya/process

Features

Buffered IO stream for STDOUT/STDERR

Process will return buffered IO for read/write

Method will return stream.

<?php
$proc = new Process(['echo', 'HelloWorld']);
$fd_out = $proc->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
$proc = new Process('sh sleep.sh');
$proc->start();
echo 'started';
$proc->join();

Chain Method for Pipe Command

Process#pipe() can PIPE programs.

Implicite connect pipe stdout -> stdin

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

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

<?php
$proc1 = new Process(['echo', 'HelloWorld']);
$proc2 = new Process(['cat']);
[$p1_out,$p1_err] = $proc1->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
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.

Resources

统计信息

  • 总下载量: 9.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固