OpenSwoole\Process\Pool::__construct

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

Declaration

<?php OpenSwoole\\Process::__construct (int $worker_num, int $ipc_type = 0, int $msgqueue_key = 0, bool $enable_coroutine = false)

Parameters

worker_num

How many worker process will be created in the process pool

ipc_type

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.

msgqueue_key

The message queue key when using system msg queue.

enable_coroutine

If to enable the coroutine support in the process

Return

Description

Create a pool of processes. There are 3 modes to communicate with and sending new task messages to the worker pool: with MQ like Redis or with system msg queue, or with Socket.

Example

<?php
$pool = new OpenSwoole\Process\Pool(2, OpenSwoole\Constant::IPC_SOCKET);

$pool->on("Message", function ($pool, $message) {
    echo "Message: {$message}\n";
    $pool->write("hello ");
    $pool->write("world ");
    $pool->write("\n");
});

$pool->listen('127.0.0.1', 8089);
$pool->start();
Last updated on September 20, 2022