/** * Constructor. * * @param $nEnvironment @type integer Environment. * @param $sProviderCertificateFile @type string Provider certificate file * with key (Bundled PEM). * @throws ApnsPHP_Push_Server_Exception if is unable to * get Shared Memory Segment or Semaphore ID. */ public function __construct($nEnvironment, $sProviderCertificateFile) { parent::__construct($nEnvironment, $sProviderCertificateFile); $this->_nParentPid = posix_getpid(); $this->_hShm = shm_attach(mt_rand(), self::SHM_SIZE); if ($this->_hShm === false) { throw new ApnsPHP_Push_Server_Exception('Unable to get shared memory segment'); } $this->_hSem = sem_get(mt_rand()); if ($this->_hSem === false) { throw new ApnsPHP_Push_Server_Exception('Unable to get semaphore id'); } register_shutdown_function(array($this, 'onShutdown')); pcntl_signal(SIGCHLD, array($this, 'onChildExited')); foreach (array(SIGTERM, SIGQUIT, SIGINT) as $nSignal) { pcntl_signal($nSignal, array($this, 'onSignal')); } }