17
cron
cron_run
SYNOPSIS
cron_run()
DESCRIPTION
cron_run executes all the scripts *.php in the cron directory at the root of the site or the service. See the constant CRON_DIR.
cron_run must be run regularly by the cron deamon on Linux or the Task Scheduler on Windows.
See the file CRONTAB at the root of the site or the service.
If cron_run is already running, the function returns false. Otherwise, cron_run returns true.
See the script cron_newsletter.php in CRON_DIR which calls newsletter_post to send all pending newsletters.
- require_once 'models/newsletter.inc';
- newsletter_post();
CODE
- require_once 'registry.php';
Loads the code of the function registry.
- define('CRON_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'cron');
Defines the directory where the scripts run by cron_run are located.
- function cron_run() {
- $files=glob(CRON_DIR . DIRECTORY_SEPARATOR . '*.php');
- if (!$files) {
- return true;
- }
- $now=time();
- $semaphore = registry_get('cron_lock', false);
- if ($semaphore) {
- if ($now - $semaphore < 3600) {
- return false;
- }
- }
- registry_set('cron_last', $now);
- registry_set('cron_lock', $now);
- foreach ($files as $f) {
- include $f;
- }
- registry_delete('cron_lock');
- return true;
- }
cron_cleanup
SYNOPSIS
cron_cleanup()
DESCRIPTION
cron_cleanup removes the lock set by cron_run.
CODE
- function cron_cleanup() {
- registry_delete('cron_lock');
- }
Comments