Swoole Server addProcess

public boolean Swoole\Server::addProcess ( swoole_process $process )

Alias: Swoole\Server->addProcess( swoole_process $process )

<?php
bool Swoole\Server->addProcess(swoole_process $process)

Add a user defined child process to the server. The process can be used as monitoring or other tasks.

Parameter

Return

The return value indicates the result of add proccess to swoole server.

Example:
<?php
$server = new Swoole\Server('127.0.0.1', 9501);

$process = new Swoole\Process(function($process) use ($server) {
    while (true) {
        $msg = $process->read();
        foreach($server->connections as $conn) {
            $server->send($conn, $msg);
        }
    }
});

$server->addProcess($process);

$server->on('receive', function ($serv, $fd, $from_id, $data) use ($process) {
    // send the data received to all the child processes
    $process->write($data);
});

$server->start();