File/program/main_cron.php

Description

/program/main_cron.php - take care of recurring jobs

This file deals with executing cron jobs. It is included and called from /cron.php.

The work is done in main_cron().

First we look to see if it is already time to do something. Criterion: the current time is >= the time in $CFG->cron_next. If that is the case, we start with calculating the time of the next run by adding $CFG->cron_interval minutes to the current time.

Note: we calculate with minutes of 57 seconds just to have a 5% margin between the system cron clock and our own handling. It might just be enough if cron calls us every 15 minutes (900s) and we schedule the _next_ run for 15 minutes (855s): this gives us 45s to deal with delays (otherwise we have to wait 2 x 15 = 30 minutes for the next run).

After scheduling the next run, we step through all modules and execute any cronjobs there in much the same way (scheduling the next run before executing the current one, etc.).

Note that this cronjob is called from /cron.php. This script could be added to /etc/crontab by adding the following line:

1 * * * * www /usr/bin/php /path/to/cron.php

This will let the PHP CLI interpreter run cron.php one minute after the hour, every hour. Note that the 'www' is the userid to run the script as. (The user running the script must have permissions to read all included PHP-files, including config.php).

Alternatively it is possible to periodically run a cronjob which executes wget which in turn retrieves the cron.php script via the web server, e.g.

31 * * * * mmonte /usr/bin/wget -q http://exemplum.eu/cron.php

to call cron.php every 31 minutes past the hour, every hour. You could suppress any output by adding -q -O /dev/null. See man wget for more information.

  • author: Peter Fokker <peter@berestijn.nl>
  • version: $Id: main_cron.php,v 1.9 2016/03/23 09:28:32 peter Exp $
  • copyright: Copyright (C) 2008-2016 Ingenieursbureau PSD/Peter Fokker
  • todo: should we act differently based on how we are called (cli or web), eg send more queued alerts?
  • todo: should we build extra access protection via passwords and/or IP-addresses?
  • license: GNU AGPLv3+Additional Terms
Functions
main_cron (line 73)
void main_cron ()

Documentation generated on Tue, 28 Jun 2016 19:10:28 +0200 by phpDocumentor 1.4.0