PHPDaemon\Thread\Collection::push PHP Method

push() public method

Pushes certain thread to the collection
public push ( Generic $thread ) : void
$thread Generic
return void
    public function push(Generic $thread)
    {
        $id = ++$this->spawnCounter;
        $thread->setId($id);
        $this->threads[$id] = $thread;
    }

Usage Example

Example #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;
 }
All Usage Examples Of PHPDaemon\Thread\Collection::push