diff --git a/CHANGELOG b/CHANGELOG index f51b4c51..06f2226f 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ - Adding Portuguese / Brazilian language file (thanks to Luiz Alberto S. Ribeiro). - Large status page by Michael Greenhill. - New config file (see install instructions in README). +- Cronjob will be prevented from running multiple times at the same time (with a 10 mins timeout). ######################### # diff --git a/README.md b/README.md index 057fb35c..f0c93957 100755 --- a/README.md +++ b/README.md @@ -125,6 +125,9 @@ If it is your own server or you have shell access and permission to open the cro As you can see, this line will run the status.cron.php script every 15 minutes. Change the line to suit your needs. If you do not have shell access, ask your web hosting provider to set it up for you. +The update script has been designed to prevent itself from running multiple times. It has a maximum timeout of 10 minutes. +After that the script is assumed dead and the cronjob will run again. + ## CUSTOMIZING diff --git a/cron/status.cron.php b/cron/status.cron.php index 9bd43e3a..c059304f 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -28,6 +28,15 @@ // include main configuration and functionality require_once dirname(__FILE__) . '/../src/bootstrap.php'; +// prevent cron from running twice at the same time +// however if the cron has been running for 10 mins, we'll assume it died and run anyway +$time = time(); +if(psm_get_conf('cron_running') == 1 && ($time - psm_get_conf('cron_running_time') < 600)) { + die('Cron is already running. Exiting.'); +} +psm_update_conf('cron_running', 1); +psm_update_conf('cron_running_time', $time); + // get the active servers from database $servers = $db->select( PSM_DB_PREFIX.'servers', @@ -70,4 +79,6 @@ foreach ($servers as $server) { ); } +psm_update_conf('cron_running', 0); + ?> \ No newline at end of file diff --git a/src/psm/Util/Install/Queries.class.php b/src/psm/Util/Install/Queries.class.php index 4c231881..2729b170 100644 --- a/src/psm/Util/Install/Queries.class.php +++ b/src/psm/Util/Install/Queries.class.php @@ -110,13 +110,17 @@ class Queries { ('version', '{$version}'), ('auto_refresh_servers', '0'), ('show_update', '1'), - ('last_update_check', '0');"; + ('last_update_check', '0'), + ('cron_running', '0'), + ('cron_running_time', '0');"; } else { if(version_compare($version_from, '2.1.0', '<')) { // 2.0 upgrade $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP `config_id`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` ADD PRIMARY KEY ( `key` );"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP INDEX `key`;"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('cron_running', '0');"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('cron_running_time', '0');"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `error` `error` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `rtime` `rtime` FLOAT( 9, 7 ) NULL;";