Cronjob
The configuration of the jobs is located in /etc/crontab (on Debian based distributions).
Before adding a entry you need to know how you can define the execution interval:
# * * * * * command to execute # ┬ ┬ ┬ ┬ ┬ # │ │ │ │ │ # └─│─│─│─│────────── min (0 - 59) # └─│─│─│────────── hour (0 - 23) # └─│─│────────── day of month (1 - 31) # └─│────────── month (1 - 12) # └────────── day of week (0 - 6) (Sunday to Saturday, for example 0 equals Sunday and 4 Thursday)
For example if you want to run a job every half hour you have to set the params 30 * * * *
or 0 0 1 1 * runs once a year at midnight in the morning of January 1
Webcron
Pseudo-cron
The pseuco-cron feature from CONTENIDO adapts the general logic from the default cron feature. The difference between the two implementations is that cronjobs are controlled through a operating system timer and the CONTENIDO pseudo cron 'timer' is a call of the frontend.
All cronjobs are located at the directory: 'contenido/cronjobs'. The main configuration for cronjobs is contained in the file :'data/cronlog/crontab.txt'. In this file you can define the execution time for a cronjob file. The last execution time of every cronjob is stored in a file with the name (name.php.job) of the cronjob containing a timestamp of the last execution. The call of the frontend performs a check if the difference of the last execution time and the actual time is bigger than the defined execution time/period in the contab.txt and the cronjob will be executed in this case.
Activation/Deactivation
The pseudo-cron feature is enabled as default setting. If you want to deactivate it (this is highly recommended if you want to run your files with real cronjobs instead) you have to set cfg['use_pseudocron'] = false; in the config.misc.php (line 36).
Core cronjobs
Name | Description | Execution time |
---|---|---|
advance_workflow.php | This cronjob activates the next workflow step if the time limit is over | - |
linkchecker.php | Checks all links | #02 1 * * * (deactivated with #) |
move_articles.php | Move articles at specified time | */1 * * * * (periodically every minute) |
move_old_stats.php | This cronjob is used to move old statistics into the stat_archive table | 0 0 1 * * (every first day in the month at midnight) |
optimize_database.php | This cronjob optimizes all database tables | 0 0 * * *Â (every full hour) |
run_newsletter_job.php | Cronjob for newsletter plugin | - |
send_reminder.php | Cronjob to send the reminder items. | */5 * * * * (periodically every 5 minutes) |
setfrontenduserstate.php | Â Activate/deactivate frontend users by time. | */5 * * * * (periodically every 5 minutes) |
Adding new cronjobs
To add a new cronjob you have to create a new cronjob file at 'contenido/cronjobs' (use the template below if you want) and configure it´s execution period at the 'data/cronlog/crontab.txt' file.
Cronjob plugin
The CONTENIDO cronjob plugin (default: not installed) provides information about the cronjobs and the possibility to configure cronjobs in the backend mode. A further feature is to start a cronjob manually.
Cronjob template:
<?php /** * Template cronjob file * * @package Core * @subpackage Cronjob * * @author claus.schunk@4fb.de * @copyright four for business AG <www.4fb.de> * @license http://www.contenido.org/license/LIZENZ.txt * @link http://www.4fb.de * @link http://www.contenido.org */ if (!defined('CON_FRAMEWORK')) { define('CON_FRAMEWORK', true); } // CONTENIDO path $contenidoPath = str_replace('\\', '/', realpath(dirname(__FILE__) . '/../')) . '/'; // CONTENIDO startup process include_once($contenidoPath . 'includes/startup.php'); require_once(cRegistry::getBackendPath() . $cfg['path']['includes'] . 'pseudo-cron.inc.php'); if (!isRunningFromWeb() || function_exists('runJob') || $area == 'cronjobs') { //implement your code here } ?>
When developing a cronjob (a real one, not a pseudo-cronjob) it is often necessary to use functionality that is provided by plugins. In order to use this you have to include the plugins yourself. This can be achieved by adding theses lines to your code:
// include plugins & call hook after plugins are loaded $cfg = cRegistry::getConfig(); require_once $backendPath . $cfg['path']['includes'] . 'functions.includePluginConf.php'; cApiCecHook::execute('Contenido.Frontend.AfterLoadPlugins');