Swoole\Process\Manager::__construct

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Process\Manager::__construct (int $ipcType = SWOOLE_IPC_NONE, int $msgQueueKey = 0)

Parameters

ipcType

SWOOLE_IPC_NONE: disable IPC. SWOOLE_IPC_MSGQUEUE: use system msg queue for IPC, for adding new task message into the worker pool. SWOOLE_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.

Example

<?php
$pm = new Swoole\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 August 31, 2022