Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\\Process::__construct (int $worker_num, int $ipc_type = 0, int $msgqueue_key = 0, bool $enable_coroutine = false)
How many worker process will be created in the process pool
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.
The message queue key when using system msg queue.
If to enable the coroutine support in the process
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.
<?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();