Ejemplo n.º 1
0
 private function daemonize()
 {
     $this->processManager->replaceParentProcess();
     umask(0);
     if (posix_setsid() === -1) {
         $this->releaseLock();
         throw new UnableToSetsidException();
     }
     $this->processManager->replaceParentProcess();
     pcntl_signal(SIGHUP, function () {
         $this->signalHandler(SIGHUP);
     });
     pcntl_signal(SIGTERM, function () {
         $this->signalHandler(SIGTERM);
     });
     pcntl_signal(SIGINT, function () {
         $this->signalHandler(SIGINT);
     });
     pcntl_signal(SIGCHLD, function () {
         $this->signalHandler(SIGCHLD);
     });
     if (!chdir('/')) {
         $this->releaseLock();
         throw new UnableToChangeDirectoryException();
     }
     fclose(STDIN);
     fclose(STDOUT);
     fclose(STDERR);
     $STDIN = fopen('/dev/null', 'r');
     $STDOUT = fopen('/dev/null', 'wb');
     $STDERR = fopen('/dev/null', 'wb');
 }