protected function _mainLoop()
	{
		while (true) {
			pcntl_signal_dispatch();

			if (posix_getppid() != $this->_nParentPid) {
				$this->_log("INFO: Parent process {$this->_nParentPid} died unexpectedly, exiting...");
				break;
			}

			sem_acquire($this->_hSem);
			$this->_setQueue(self::SHM_ERROR_MESSAGES_QUEUE_KEY, 0,
				array_merge($this->_getQueue(self::SHM_ERROR_MESSAGES_QUEUE_KEY), parent::getErrors())
			);

			$aQueue = $this->_getQueue(self::SHM_MESSAGES_QUEUE_KEY_START, $this->_nCurrentProcess);
			foreach($aQueue as $message) {
				parent::add($message);
			}
			$this->_setQueue(self::SHM_MESSAGES_QUEUE_KEY_START, $this->_nCurrentProcess);
			sem_release($this->_hSem);

			$nMessages = count($aQueue);
			if ($nMessages > 0) {
				$this->_log('INFO: Process ' . ($this->_nCurrentProcess + 1) . " has {$nMessages} messages, sending...");
				parent::send();
			} else {
				usleep(self::MAIN_LOOP_USLEEP);
			}
		}
	}
protected function _mainLoop()
	{
		while (true) {
			pcntl_signal_dispatch();

			if (posix_getppid() != $this->_nParentPid) {
				$this->_log("INFO: Parent process {$this->_nParentPid} died unexpectedly, exiting...");
				break;
			}

			sem_acquire($this->_hSem);
			$this->_setQueue(self::SHM_ERROR_MESSAGES_QUEUE_KEY, 0,
				array_merge($this->_getQueue(self::SHM_ERROR_MESSAGES_QUEUE_KEY), parent::getErrors())
			);

			$aQueue = $this->_getQueue(self::SHM_MESSAGES_QUEUE_KEY_START, $this->_nCurrentProcess);
			foreach($aQueue as $message) {
				parent::add($message);
			}
			$this->_setQueue(self::SHM_MESSAGES_QUEUE_KEY_START, $this->_nCurrentProcess);
			sem_release($this->_hSem);

			$nMessages = count($aQueue);
			if ($nMessages > 0) {
				$this->_log('INFO: Process ' . ($this->_nCurrentProcess + 1) . " has {$nMessages} messages, sending...");
				parent::send();
			} else {
				usleep(self::MAIN_LOOP_USLEEP);
			}
		}
	}
protected function _mainLoop ( ) { while ( true ) { pcntl_signal_dispatch ( ) ; if ( posix_getppid ( ) != $ this -> _nParentPid ) { $ this -> _log ( "INFO: Parent process {$this->_nParentPid} died unexpectedly, exiting..." ) ; break ; } sem_acquire ( $ this -> _hSem ) ; $ this -> _setQueue ( self :: SHM_ERROR_MESSAGES_QUEUE_KEY , 0 , array_merge ( $ this -> _getQueue ( self :: SHM_ERROR_MESSAGES_QUEUE_KEY ) , parent :: getErrors ( ) ) ) ; $ aQueue = $ this -> _getQueue ( self :: SHM_MESSAGES_QUEUE_KEY_START , $ this -> _nCurrentProcess ) ; foreach ( $ aQueue as $ message ) { parent :: add ( $ message ) ; } $ this -> _setQueue ( self :: SHM_MESSAGES_QUEUE_KEY_START , $ this -> _nCurrentProcess ) ; sem_release ( $ this -> _hSem ) ; $ nMessages = count ( $ aQueue ) ; if ( $ nMessages > 0 ) { $ this -> _log ( 'INFO: Process ' . ( $ this -> _nCurrentProcess + 1 ) . " has {$nMessages} messages, sending..." ) ; parent :: send ( ) ; } else { usleep ( self :: MAIN_LOOP_USLEEP ) ; } } }
The process main loop.

During the main loop: the per-process error queue is read and the common error message
container is populated; the per-process message queue is spooled (message from
this queue is added to ApnsPHP_Push queue and delivered).
The process main loop .