/** * Execution commands. * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { if (is_null(Config::$sharedId) == false && @shm_has_var(Config::$sharedId, Config::PID)) { $output->writeln('<info>' . Config::NAME . ' ' . shm_get_var(Config::$sharedId, Config::PID) . ' is running</info>'); exit; } if ($input->getOption('debug') === false) { if (function_exists('ini_set')) { ini_set('error_log', Config::$path . Config::$logsPath . '/error.log'); } fclose(STDIN); fclose(STDOUT); fclose(STDERR); $STDIN = fopen('/dev/null', 'r'); $STDOUT = fopen(Config::$path . Config::$logsPath . '/appilication.log', 'ab'); $STDERR = fopen(Config::$path . Config::$logsPath . '/error.log', 'ab'); } $phpcron = new PHPCron(Entries::getCrontab()); $phpcron->execute(); }
/** * Execution records individually. * @param integer $id * @param array $entrie * @return boolean */ protected function execEntrie($id, $entrie) { $pid = pcntl_fork(); if ($pid == -1) { return false; } elseif ($pid) { $this->running[$pid] = $id; } else { while (is_null(Config::$sharedId) == false && @shm_has_var(Config::$sharedId, Config::PID)) { $currentTime = new \DateTime(); if (Entries::check($entrie, $currentTime)) { $process = new Process($entrie['cmd']); $process->run(); if ($process->isSuccessful()) { sleep(Config::setSleep($entrie, $currentTime)); exit; } } else { sleep(Config::setSleep($entrie, $currentTime)); } } exit; } }