Esempio n. 1
0
 /**
  * Fork process and kill parent process, the heart of the 'daemonization'
  *
  * @return boolean
  */
 protected static function _fork()
 {
     self::log(self::LOG_DEBUG, "forking " . self::getOption("appName") . " daemon", __FILE__, __CLASS__, __FUNCTION__, __LINE__);
     $pid = pcntl_fork();
     if ($pid == -1) {
         // Error
         self::log(self::LOG_WARNING, "" . self::getOption("appName") . " daemon could not be forked", __FILE__, __CLASS__, __FUNCTION__, __LINE__);
         return false;
     } else {
         if ($pid) {
             // Parent
             self::log(self::LOG_DEBUG, "ending " . self::getOption("appName") . " parent process", __FILE__, __CLASS__, __FUNCTION__, __LINE__);
             // Die without attracting attention
             exit;
         } else {
             // Child
             self::$_processIsChild = true;
             self::$_isDying = false;
             self::$_processId = posix_getpid();
             return true;
         }
     }
 }
Esempio n. 2
0
 /**
  * Fork process and kill parent process, the heart of the 'daemonization'
  *
  * @return boolean
  */
 protected static function _fork()
 {
     self::debug('forking {appName} daemon');
     $pid = pcntl_fork();
     if ($pid === -1) {
         // Error
         return self::warning('Process could not be forked');
     } else {
         if ($pid) {
             // Parent
             self::debug('Ending {appName} parent process');
             // Die without attracting attention
             exit;
         } else {
             // Child
             self::$_processIsChild = true;
             self::$_isDying = false;
             self::$_processId = posix_getpid();
             return true;
         }
     }
 }
Esempio n. 3
0
 /**
  * Fork process and kill parent process, the heart of the 'daemonization'
  *
  * @return boolean
  */
 protected static function _fork()
 {
     self::debug('forking {appName} daemon');
     $pid = pcntl_fork();
     if ($pid === -1) {
         // Error
         return self::warning('Process could not be forked');
     } else {
         if ($pid) {
             // Parent
             self::debug('Ending {appName} parent process');
             // Additional PID succeeded check
             if (!is_numeric($pid)) {
                 self::emerg('No valid pid: %s', $pid);
                 exit(-1);
             }
             // Change umask
             @umask(0);
             // Write pidfile
             $p = self::_writePid(self::opt('appPidLocation'), $pid);
             if (false === $p) {
                 self::emerg('Unable to write pid file {appPidLocation}');
                 exit(-1);
             }
             // Die without attracting attention
             exit;
         } else {
             // Child
             self::$_processIsChild = true;
             self::$_isDying = false;
             self::$_processId = posix_getpid();
             return true;
         }
     }
 }