PHPDaemon\Thread\Master::spawnWorkers PHP Method

spawnWorkers() protected method

Spawn new worker processes
protected spawnWorkers ( $n ) : boolean
$n - integer - number of workers to spawn
return boolean - success
    protected function spawnWorkers($n)
    {
        if (FileSystem::$supported) {
            eio_event_loop();
        }
        $n = (int) $n;
        for ($i = 0; $i < $n; ++$i) {
            $thread = new Worker();
            $this->workers->push($thread);
            $this->callbacks->push(function ($self) use($thread) {
                // @check - is it possible to run iterate of main event loop without child termination?
                $thread->start();
                $pid = $thread->getPid();
                if ($pid < 0) {
                    Daemon::$process->log('could not fork worker');
                } elseif ($pid === 0) {
                    // worker
                    Daemon::log('Unexcepted execution return to outside of Thread->start()');
                    exit;
                }
            });
        }
        if ($n > 0) {
            $this->lastMpmActionTs = microtime(true);
            if (EventLoop::$instance) {
                EventLoop::$instance->interrupt();
            }
        }
        return true;
    }