首页 Order Swoole4 正文

Swoole4 [进程管理] 进程管理器(Process\Manager)

金鹏头像 金鹏 Swoole4 2022-01-02 14:01:33 0 881
导读:Process\Manager进程管理器,基于Process\Pool实现。可以管理多个进程。相比与Process\Pool,可以非常方便的创建多个执行不同任务的进程,并且可...

Process\Manager

进程管理器,基于 Process\Pool 实现。可以管理多个进程。相比与 Process\Pool,可以非常方便的创建多个执行不同任务的进程,并且可以控制每一个进程是否要处于协程环境。

版本支持情况

版本号类名更新说明
v4.5.3Swoole\Process\ProcessManager-
v4.5.5Swoole\Process\Manager重命名,ProcessManager 为 Manager 的别名

v4.5.3 以上的版本可用。

使用示例

use Swoole\Process\Manager;
use Swoole\Process\Pool;

$pm = new Manager();

for ($i = 0; $i < 2; $i++) {
    $pm->add(function (Pool $pool, int $workerId) {
    });
}

$pm->start();

方法

__construct()

构造方法。

Swoole\Process\Manager::__construct(int $ipcType = SWOOLE_IPC_NONE, int $msgQueueKey = 0);
  • 参数

    • 功能:消息队列的 key,和 Process\Pool$msgqueue_key 一致

    • 默认值:无

    • 其它值:无

    • 功能:进程间通信的模式,和 Process\Pool$ipc_type 一致【默认为 0 表示不使用任何进程间通信特性】

    • 默认值0

    • 其它值:无

    • int $ipcType

    • int $msgQueueKey

setIPCType()

设置工作进程之间的通信方式。

Swoole\Process\Manager->setIPCType(int $ipcType): self;
  • 参数

    • 功能:进程间通信的模式

    • 默认值:无

    • 其它值:无

    • int $ipcType

getIPCType()

获取工作进程之间的通信方式。

Swoole\Process\Manager->getIPCType(): int;

setMsgQueueKey()

设置消息队列的 key

Swoole\Process\Manager->setMsgQueueKey(int $msgQueueKey): self;
  • 参数

    • 功能:消息队列的 key

    • 默认值:无

    • 其它值:无

    • int $msgQueueKey

getMsgQueueKey()

获取消息队列的 key

Swoole\Process\Manager->getMsgQueueKey(): int;

add()

增加一个工作进程。

Swoole\Process\Manager->add(callable $func, bool $enableCoroutine = false): self;
  • 参数

    • 功能:是否为这个进程创建协程来执行回调函数

    • 默认值:false

    • 其它值:无

    • 功能:当前进程执行的回调函数

    • 默认值:无

    • 其它值:无

    • callable $func

    • bool $enableCoroutine

addBatch()

批量增加工作进程。

Swoole\Process\Manager->addBatch(int $workerNum, callable $func, bool $enableCoroutine = false): self
  • 参数

    • 功能:是否为这些进程创建协程来执行回调函数

    • 默认值:无

    • 其它值:无

    • 功能:这些进程执行的回调函数

    • 默认值:无

    • 其它值:无

    • 功能:批量增加进程的个数

    • 默认值:无

    • 其它值:无

    • int $workerNum

    • callable $func

    • bool $enableCoroutine

start()

启动工作进程。

Swoole\Process\Manager->start(): void
本文地址:https://www.jinpeng.work/?id=106
若非特殊说明,文章均属本站原创,转载请注明原链接。
广告3

欢迎 发表评论:

  • 请填写验证码

日历

«    2025年4月    »
123456
78910111213
14151617181920
21222324252627
282930

控制面板

您好,欢迎到访网站!
  查看权限
广告2

退出请按Esc键