Swoole\Process\ProcessManager->add

Declaration

<?php
Swoole\Process\ProcessManager->add (callable $func, bool $enableCoroutine = false)

Parameters

func

The function to be executed in the process.

enableCoroutine

If enable coroutine support within the process

Return

Description

Add a function to be executed in the process.

Example

<?php
$pm = new Swoole\Process\ProcessManager();
$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();