validateInput($config['debug']); $config['memory_limit'] = $filter->validateInput($config['memory_limit']); $config['wsdl_cache'] = $filter->validateInput($config['wsdl_cache'],'int'); $config['time_zone'] = $filter->validateInput($config['time_zone']); // Do not change any of these settings directly, use env.ini instead ini_set('display_errors', $config['debug']); ini_set('error_reporting', $e_all); ini_set('short_open_tag', 'On'); ini_set('default_charset', "UTF-8"); ini_set('memory_limit', $config['memory_limit']); ini_set('soap.wsdl_cache_enabled', $config['wsdl_cache']); ini_set('date.timezone', $config['time_zone']); define ('DEBUG_SQL_LOG', $config['debug_sql']); define ('DEBUG_TIME_LOG', $config['debug_time']); define ('DEBUG_CALENDAR_LOG', $config['debug_calendar']); define ('MEMCACHED_ENABLED', $config['memcached']); define ('MEMCACHED_SERVER', $config['memcached_server']); define ('TIME_ZONE', $config['time_zone']); //Cron status $bCronIsRunning = false; $sLastExecution = null; $processcTimeProcess = 0; $processcTimeStart = 0; $force = false; $osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN"; for ($i = 1; $i <= count($argv) - 1; $i++) { if (strpos($argv[$i], "+force") !== false) { $force = true; unset($argv[$i]); break; } } if (!$force && file_exists(PATH_DATA . "cron")) { //Windows flag //Get data of cron file $arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "cron"))); $bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]); $sLastExecution = $arrayCron["sLastExecution"]; $processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes $processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0; } if (!$force && $osIsLinux) { //Linux flag //Check if cron it's running exec("ps -fea | grep cron.php | grep -v grep", $arrayOutput); if (count($arrayOutput) > 1) { $bCronIsRunning = true; } } //if (!$force && $bCronIsRunning && $processcTimeStart != 0) { // if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) { // //Cron finished his execution for some reason // $bCronIsRunning = false; // } //} if ($force || !$bCronIsRunning) { //Start cron $arrayCron = array("bCronIsRunning" => "1", "sLastExecution" => date("Y-m-d H:i:s")); @file_put_contents(PATH_DATA . "cron", serialize($arrayCron)); try { //Data $ws = null; $argsx = null; $sDate = null; $dateSystem = date("Y-m-d H:i:s"); for ($i = 1; $i <= count($argv) - 1; $i++) { if (!isset($argv[$i])) { continue; } if (strpos($argv[$i], "+d") !== false) { $sDate = substr($argv[$i],2); } else { if (strpos($argv[$i], "+w") !== false) { $ws = substr($argv[$i], 2); } else { $argsx = $argsx . " " . $argv[$i]; } } } //If $sDate is not set, so take the system time if (!empty($sDate) && preg_match("/^[1-9]\d{3}\-(?:0[1-9]|1[0-2])\-(?:0[1-9]|[12][0-9]|3[01])(?:\s(?:[0-1]\d|2[0-3])\:[0-5]\d\:[0-5]\d)?$/", $sDate)) { eprintln("[Applying date filter: $sDate]"); } else { $sDate = $dateSystem; } if ($ws == null) { $oDirectory = dir(PATH_DB); $cws = 0; while (($sObject = $oDirectory->read()) !== false) { if (($sObject != ".") && ($sObject != "..")) { if (is_dir(PATH_DB . $sObject)) { if (file_exists(PATH_DB . $sObject . PATH_SEP . "db.php")) { $cws = $cws + 1; system("php -f \"" . dirname(__FILE__) . PATH_SEP . "cron_single.php\" $sObject \"$sDate\" \"$dateSystem\" $argsx", $retval); } } } } } else { if (!is_dir(PATH_DB . $ws) || !file_exists(PATH_DB . $ws . PATH_SEP . "db.php")) { throw new Exception("Error: The workspace \"$ws\" does not exist"); } $cws = 1; system("php -f \"" . dirname(__FILE__) . PATH_SEP . "cron_single.php\" $ws \"$sDate\" \"$dateSystem\" $argsx", $retval); } eprintln("Finished $cws workspaces processed."); } catch (Exception $e) { eprintln("Has produced the following error:", "red"); eprintln("* " . $e->getMessage()); eprintln("[DONE]", "green"); } //End cron $arrayCron = array("bCronIsRunning" => "0", "sLastExecution" => date("Y-m-d H:i:s")); @file_put_contents(PATH_DATA . "cron", serialize($arrayCron)); } else { eprintln("The cron is running, please wait for it to finish.\nStarted in $sLastExecution"); eprintln("If do you want force the execution use the option '+force', example: php -f +wworkflow +force" ,"green"); }