cron.php
changeset 289 a92002aa470b
parent 285 e72bf2c24875
child 294 444c34a3886b
equal deleted inserted replaced
288:30ef6b618795 289:a92002aa470b
    18 
    18 
    19 // The cron script is triggered by way of an image. This is a 1x1px transparent GIF.
    19 // The cron script is triggered by way of an image. This is a 1x1px transparent GIF.
    20 define('ENANO_GIF_SPACER', base64_decode('R0lGODlhAQABAIAAAP///////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwAAAAAAQABAAACAkwBADs='));
    20 define('ENANO_GIF_SPACER', base64_decode('R0lGODlhAQABAIAAAP///////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwAAAAAAQABAAACAkwBADs='));
    21 
    21 
    22 // Don't need a page to load, all we should need is the Enano API
    22 // Don't need a page to load, all we should need is the Enano API
    23 $_GET['title'] = 'Enano:Cron';
       
    24 require('includes/common.php');
    23 require('includes/common.php');
    25 
    24 
    26 global $db, $session, $paths, $template, $plugins; // Common objects
    25 global $db, $session, $paths, $template, $plugins; // Common objects
    27 
    26 
    28 // Hope now that plugins are loaded :-)
    27 // Hope now that plugins are loaded :-)
    29 $last_run = ( $x = getConfig('cron_last_run') ) ? $x : 0;
       
    30 $time = strval(time());
       
    31 setConfig('cron_last_run', $time);
       
    32 
       
    33 global $cron_tasks;
    28 global $cron_tasks;
    34 
    29 
    35 foreach ( $cron_tasks as $interval => $tasks )
    30 foreach ( $cron_tasks as $interval => $tasks )
    36 {
    31 {
    37   $last_run_threshold = time() - ( $interval * 3600 );
    32   $last_run = intval(getConfig("cron_lastrun_ivl_$interval"));
       
    33   $last_run_threshold = time() - ( 3600 * $interval );
    38   if ( $last_run_threshold >= $last_run )
    34   if ( $last_run_threshold >= $last_run )
    39   {
    35   {
    40     foreach ( $tasks as $task )
    36     foreach ( $tasks as $task )
    41     {
    37     {
    42       @call_user_func($task);
    38       @call_user_func($task);
    43     }
    39     }
       
    40     setConfig("cron_lastrun_ivl_$interval", strval(time()));
    44   }
    41   }
    45 }
    42 }
    46 
    43 
    47 header('Pragma: no-cache');
    44 header('Pragma: no-cache');
    48 header('Cache-control: no-cache');
    45 header('Cache-control: no-cache');