/** * Check the record. * @param array $entrie * @param DateTime $time * @return boolean */ public static function check($entrie, $time) { $time = Config::formatTime($time); foreach ($time as $type => $value) { if ($type == 'year') { continue; } if (($type == 'month' || $type == 'dow') && is_string($entrie[$type]) && array_key_exists($entrie[$type], Config::$txtToInt[$type])) { $entrie[$type] = Config::$txtToInt[$type][$entrie[$type]]; } // example: * if ($entrie[$type] == '*') { continue; } // example: 23 if (is_numeric($entrie[$type]) && (int) $entrie[$type] <= Config::$maximum[$type] && $value == (int) $entrie[$type]) { continue; } // example: */15 if (preg_match("/^\\*\\/(\\d+)\$/", $entrie[$type], $out)) { if (is_numeric($out[1]) && (int) $out[1] <= Config::$maximum[$type] && $value % (int) $out[1] == 0) { continue; } } // example: 5-15 if (preg_match("/^(\\d+)\\-(\\d+)\$/", $entrie[$type], $out)) { if (is_numeric($out[1]) && is_numeric($out[2]) && (int) $out[1] <= Config::$maximum[$type] && $out[2] <= Config::$maximum[$type] && $out[2] > $out[1] && $value >= $out[1] && $value <= $out[2]) { continue; } } // example: 5-15/2 if (preg_match("/^(\\d+)\\-(\\d+)\\/(\\d+)\$/", $entrie[$type], $out)) { if (is_numeric($out[1]) && is_numeric($out[2]) && is_numeric($out[3]) && (int) $out[1] <= Config::$maximum[$type] && $out[2] <= Config::$maximum[$type] && $out[3] <= Config::$maximum[$type] && $out[2] > $out[1] && $value >= $out[1] && $value <= $out[2] && $value % (int) $out[3] == 0) { continue; } } // example: 5,7,12 $out = explode(',', $entrie[$type]); if (count($out) > 1 && in_array($value, $out)) { $key = array_search($value, $out); if (is_numeric($out[$key]) && (int) $out[$key] <= Config::$maximum[$type]) { continue; } } return false; } return true; }
/** * Setting up the system, setting parameters. */ public function __construct() { if (function_exists('ini_set') && extension_loaded('xdebug')) { ini_set('xdebug.show_exception_trace', false); ini_set('xdebug.scream', false); } if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) { date_default_timezone_set(@date_default_timezone_get()); } if (stripos(\Phar::running(), 'phar:') !== false) { Config::$path = '/var/phpcron/'; } $this->createPatch(); Config::$sharedId = shm_attach(ftok(__FILE__, 'A')); parent::__construct(strtolower(Config::NAME), Config::VERSION); }
/** * 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; } }