OpenSwoole\Core\Process\Manager::__construct

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Core\Process\Manager::__construct (int $ipcType = OpenSwoole\Constant::IPC_NONE, int $msgQueueKey = 0)

Parameters

ipcType

OpenSwoole\Constant::IPC_NONE: disable IPC. OpenSwoole\Constant::IPC_MSGQUEUE: use system msg queue for IPC, for adding new task message into the worker pool. OpenSwoole\Constant::IPC_SOCKET: use Socket for IPC.

msgQueueKey

The message queue key when using system msg queue.

Return

Description

Create a process manager. You can add multiple function into the process manager and execute them in multiple worker processes.

You have to install OpenSwoole core library with composer require openswoole/core to use this feature.

Example

<?php
$pm = new OpenSwoole\Core\Process\Manager();
$atomic = new Atomic(0);
$pm->add(function (Pool $pool, int $workerId) use ($atomic) {
    usleep(100000);
    $atomic->wakeup();
});
$pm->add(function (Pool $pool, int $workerId) use ($atomic) {
    $atomic->wait(1.5);
    $pool->shutdown();
});
$pm->start();
Last updated on February 9, 2023