Download the PHP package workbunny/process without Composer
On this page you can find all versions of the php package workbunny/process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download workbunny/process
More information about workbunny/process
Files in workbunny/process
Package process
Short Description A lightweight multi-process helper base on PHP.
License MIT
Homepage https://github.com/process
Informations about the package process
workbunny/process
🐇 A lightweight multi-process helper base on PHP. 🐇
简介
这是一个基于ext-pcntl和ext-posix拓展的PHP多进程助手,用于更方便的调用使用。
快速开始
-
创建一个子Runtime
-
父Runtime执行
-
快速创建运行多个子Runtime
- 监听子Runtime
方法
注:作用范围为父Runtime的方法仅在父Runtime内有有效响应
方法名 | 作用范围 | 是否产生分叉 | 描述 |
---|---|---|---|
child() | parentContext | √ | 分叉一个子Runtime / 替换一个子Runtime |
run() | parentContext | √ | 快速分叉N个子Runtime |
wait() | parentContext | × | 监听所有子Runtime状态 |
parent() | parentContext | × | 为父Runtime增加回调响应 |
isChild() | public | × | 判断是否是子Runtime |
getId() | public | × | 获取当前Runtime序号 |
getPid() | public | × | 获取当前RuntimePID |
getPidMap() | parentContext | × | 获取所有子RuntimePID |
number() | parentContext | × | 获取Runtime数量 or 产生子Runtime自增序号 |
setConfig() | public | × | 设置config |
getConfig() | public | × | 获取config |
getPidMap() | parentContext | × | 获取所有子RuntimePID |
setPriority() | public | × | 为当前Runtime设置优先级 需要当前执行用户为super user |
getPriority() | public | × | 获取当前Runtime优先级 |
exit() | public | × | 进程退出 |
说明
1. 初始化
- Runtime对象初始化支持配置
- pre_gc :接受bool值,控制Runtime在fork行为发生前是否执行PHP GC;注:Runtime默认不进行gc
- priority:接受索引数组,为所有Runtime设置优先级,索引下标对应Runtime序号; 如实际产生的Runtime数量大于该索引数组数量,则默认为0;
注:child()的priority参数会改变该默认值
注:priority需要当前用户为super user
2. fork行为
-
在 fork 行为发生后,Runtime对象会产生两个分支
- id=0 的父Runtime
- id=N 的子Runtime
-
child() 和 run() 之后的代码域会被父子进程同时执行,但相互隔离:
-
child() 函数可以进行替换子Runtime行为
- 如需在子Runtime中进行 fork 操作,请创建新的Runtime;不建议过多调用,因为进程的开销远比线程大
3. 指定执行
-
指定某个id的Runtime执行
-
指定所有子Runtime执行
- 指定父Runtime执行
4. 回调函数相关
-
所有注册的回调函数都可以接收当前的Runtime分支对象:
- 注:注册的父Runtime回调函数内传入的是父Runtime对象,注册的子Runtime回调函数内传入的参数是子Runtime对象
5. 其他
- 获取当前Runtime数量
注:该方法仅父Runtime生效
- 获取当前RuntimePID
注:该方法可结合指定执行区别获取
- 阻塞监听
注:该方法仅父Runtime生效
注:该方法在会阻塞至所有子Runtime退出
- 非阻塞监听
注:该方法仅父Runtime生效
注:该方法应配合event-loop的timer或者future进行监听
- 进程退出
注:该方法可结合指定执行区别获取
All versions of process with dependencies
ext-pcntl Version *
ext-posix Version *