Author: Vasily Zorin (maintainer@daemon.io)
Inheritance: use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog
示例#1
0
 /**
  * Spawn IPC process
  * @param $n - integer - number of workers to spawn
  * @return boolean - success
  */
 protected function spawnIPCThread()
 {
     if (FileSystem::$supported) {
         eio_event_loop();
     }
     $thread = new IPC();
     $this->ipcthreads->push($thread);
     $this->callbacks->push(function ($self) use($thread) {
         $thread->start();
         $pid = $thread->getPid();
         if ($pid < 0) {
             Daemon::$process->log('could not fork IPCThread');
         } elseif ($pid === 0) {
             // worker
             $this->log('Unexcepted execution return to outside of Thread->start()');
             exit;
         }
     });
     if ($this->eventBase) {
         $this->eventBase->stop();
     }
     return true;
 }
 /**
  * spawn new master process.
  * @return null|integer - success
  */
 public static function spawnMaster()
 {
     Daemon::$masters->push($thread = new Thread\Master());
     $thread->start();
     if (-1 === $thread->getPid()) {
         Daemon::log('could not start master');
         exit(0);
     }
     return $thread->getPid();
 }