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.

  1. require_once 'models/newsletter.inc';
  2.  
  3. newsletter_post();
CODE
  1. require_once 'registry.php';

Loads the code of the function registry.

  1. define('CRON_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'cron');

Defines the directory where the scripts run by cron_run are located.

  1. function cron_run() {
  2.     $files=glob(CRON_DIR . DIRECTORY_SEPARATOR . '*.php');
  3.  
  4.     if (!$files) {
  5.         return true;
  6.     }
  7.  
  8.     $now=time();
  9.  
  10.     $semaphore = registry_get('cron_lock', false);
  11.  
  12.     if ($semaphore) {
  13.         if ($now - $semaphore < 3600) {
  14.             return false;
  15.         }
  16.     }
  17.  
  18.     registry_set('cron_last', $now);
  19.     registry_set('cron_lock', $now);
  20.  
  21.     foreach ($files as $f) {
  22.         include $f;
  23.     }
  24.  
  25.     registry_delete('cron_lock');
  26.  
  27.     return true;
  28. }
cron_cleanup
SYNOPSIS

cron_cleanup()

DESCRIPTION

cron_cleanup removes the lock set by cron_run.

CODE
  1. function cron_cleanup() {
  2.     registry_delete('cron_lock');
  3. }
SEE ALSO

registry, index

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].