Swoole\Process\Pool->getProcess

Declaration

<?php
Swoole\Process\Pool->getProcess ( int $worker_id = 0 )

Parameters

worker_id

The worker ID

Return

Process

Swoole\Process

Description

Get the process by $worker_id. By default, it return the current process.

Example

<?php
$workerNum = 10;
$pool = new Swoole\Process\Pool($workerNum);

$pool->on("WorkerStart", function ($pool, $workerId) {
    $process = $pool->getProcess();
    $process->exec("/bin/sh", ["ls", '-l']);
});

$pool->on("WorkerStop", function ($pool, $workerId) {
    echo "Worker#{$workerId} is stopped\n";
});

$pool->start();