Ejemplo n.º 1
0
 /**
  * Check that we have a correct CLI executable of PHP.
  *
  * @return void
  */
 public function doTest()
 {
     $this->setMessage('Check if PHP may spawn processes.');
     if (!FunctionAvailabilityCheck::isFunctionDefined('proc_open')) {
         $this->markFailed('The process execution relies on proc_open, which is not available on your PHP installation.');
         return;
     }
     if (FunctionAvailabilityCheck::isFunctionBlacklistedInSuhosin('proc_open')) {
         $this->markFailed('The process execution relies on proc_open, which is disabled in Suhosin on your PHP installation. ' . 'Please remove "proc_open" from "suhosin.executor.func.blacklist" in php.ini');
         return;
     }
     if (FunctionAvailabilityCheck::isFunctionBlacklistedInPhpIni('proc_open')) {
         $this->markFailed('The process execution relies on proc_open, which is disabled in your PHP installation. ' . 'Please remove "proc_open" from "disabled_functions" in php.ini');
         return;
     }
     $this->markSuccess();
 }
Ejemplo n.º 2
0
 /**
  * Try to fork.
  *
  * The return value determines if the caller shall exit (when forking was successful and it is the forking process)
  * or rather proceed execution (is the fork or unable to fork).
  *
  * True means exit, false means go on in this process.
  *
  * @return bool
  *
  * @throws \RuntimeException When the forking caused an error.
  */
 private function fork()
 {
     /** @var LoggerInterface $logger */
     $logger = $this->getContainer()->get('logger');
     if (!$this->getContainer()->get('tenside.config')->isForkingAvailable()) {
         $logger->warning('Forking disabled by configuration, execution will block until the command has finished.');
         return false;
     } elseif (!FunctionAvailabilityCheck::isFunctionEnabled('pcntl_fork', 'pcntl')) {
         $logger->warning('pcntl_fork() is not available, execution will block until the command has finished.');
         return false;
     } else {
         $pid = pcntl_fork();
         if (-1 === $pid) {
             throw new \RuntimeException('pcntl_fork() returned -1.');
         } elseif (0 !== $pid) {
             // Tell the calling method to exit now.
             $logger->info('Forked process ' . posix_getpid() . ' to pid ' . $pid);
             return true;
         }
         $logger->info('Processing task in forked process with pid ' . posix_getpid());
         return false;
     }
 }