BUG-00000 "El script cron.php puede ser ejecutado varias veces" SOLVED

Issue:
    El script cron.php puede ser ejecutado varias veces
Cause:
    El archivo bandera "cron" trabaja bien en Windows y no asi en Linux
Solution:
    - Se ha agregado nuevas validaciones para entornos Linux
      Ejemplo: ps -fea | grep cron.php | grep -v grep
    - Se ha mejorado el codigo
This commit is contained in:
Victor Saisa Lopez
2014-08-29 12:15:33 -04:00
parent c46400ef36
commit 8503ed8ab5
4 changed files with 130 additions and 137 deletions

View File

@@ -54,33 +54,47 @@ $bCronIsRunning = false;
$sLastExecution = null;
$processcTimeProcess = 0;
$processcTimeStart = 0;
if (file_exists(PATH_DATA . "cron")) {
$force = false;
for ($i = 1; $i <= count($argv) - 1; $i++) {
if (strpos($argv[$i], "+force") !== false) {
$force = true;
unset($argv[$i]);
break;
}
}
if (!$force) {
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
$sLastExecution = $arrayCron["sLastExecution"];
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? intval($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
} else {
G::rm_dir(PATH_DATA . "cron");
}
}
if ($bCronIsRunning && $processcTimeStart != 0) {
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
//Cron finished his execution for some reason
$bCronIsRunning = false;
$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 (!$bCronIsRunning) {
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));