Exemple #1
0
function JB_do_house_keeping()
{
    global $jb_mysql_link;
    if (defined('NO_HOUSE_KEEPING')) {
        return;
    }
    $unix_time = time();
    // get the time of last run housekeep
    $sql = "SELECT * FROM `jb_variables` where `key` = 'LAST_HOUSEKEEP_RUN' ";
    if (!($result = JB_mysql_query($sql))) {
        return false;
    }
    $t_row = @mysql_fetch_array($result, MYSQL_ASSOC);
    // Poor man's lock
    //$sql = "LOCK TABLES `jb_variables` WRITE";
    //JB_mysql_query($sql)
    $sql = "UPDATE `jb_variables` SET `val`='YES' WHERE `key`='HOUSEKEEP_RUNNING' AND `val`='NO' ";
    $result = @JB_mysql_query($sql) or $DB_ERROR = mysql_error();
    if (JB_mysql_affected_rows() == 0) {
        // it is running in another proccess
        // make sure it cannot be locked for more than 30 secs
        // This is in case the proccess fails inside the lock
        // and does not release it.
        if ($unix_time > $t_row['val'] + 30) {
            // 30
            // release the lock
            $sql = "UPDATE `jb_variables` SET `val`='NO' WHERE `key`='HOUSEKEEP_RUNNING' ";
            $result = @JB_mysql_query($sql) or $DB_ERROR = mysql_error();
            // update timestamp
            $sql = "REPLACE INTO jb_variables (`key`, `val`) VALUES ('LAST_HOUSEKEEP_RUN', '{$unix_time}')  ";
            $result = @JB_mysql_query($sql) or $DB_ERROR = mysql_error();
        }
        return;
        // this function is already executing in another process.
    }
    ///////////////////////////////////////////////////////////
    // Start Critical Section - is only executed in one process at at time
    ///////////////////////////////////////////////////////////
    JB_save_session();
    // update sessions on every request
    JBPLUG_do_callback('house_keeping_critical_section', $A = false);
    // added in 3.6.1
    if ($unix_time > $t_row['val'] + 60) {
        // did 1 minute elapse since last run? 60
        // do stuff here -
        JBPLUG_do_callback('do_house_keeping', $A = false);
        // added in 3.5.0
        JB_update_all_sessions();
        // update timestamp
        $sql = "REPLACE INTO jb_variables (`key`, `val`) VALUES ('LAST_HOUSEKEEP_RUN', '{$unix_time}')  ";
        $result = @JB_mysql_query($sql) or $DB_ERROR = mysql_error();
        if (!defined('NO_HOUSE_KEEPING') && JB_CRON_EMULATION_ENABLED == 'YES') {
            set_time_limit(40);
            JB_do_cron_job();
        }
    }
    // release the poor man's lock
    $sql = "UPDATE `jb_variables` SET `val`='NO' WHERE `key`='HOUSEKEEP_RUNNING' ";
    JB_mysql_query($sql) or die(mysql_error());
    /////////////////////////////////////////////////////////////////
    // End Critical Section
}
Exemple #2
0
    if (!defined('JB_CRON_HTTP_USER')) {
        define('JB_CRON_HTTP_USER', '');
    }
    if (!defined('JB_CRON_HTTP_PASS')) {
        define('JB_CRON_HTTP_PASS', '');
    }
    if (JB_CRON_HTTP_ALLOW == 'YES') {
        if (strlen(JB_CRON_HTTP_USER) > 0) {
            // requires user/pass?
            if (!isset($_SERVER['PHP_AUTH_USER'])) {
                header('WWW-Authenticate: Basic realm="Jamit Cron"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Access Denied. Please see the user/pass on the Admin->Edit Config page, \'Cron Settings\'.';
                exit;
            } else {
                if ($_SERVER['PHP_AUTH_USER'] !== JB_CRON_HTTP_USER && $_SERVER['PHP_AUTH_PW'] !== JB_CRON_HTTP_PASS) {
                    header('WWW-Authenticate: Basic realm="Jamit Cron"');
                    header('HTTP/1.0 401 Unauthorized');
                    die('Login Failed. Please see the user/pass on the Admin->Edit Config page, \'Cron Settings\'');
                }
            }
        }
    } else {
        die('This script cannot be executed from the web browser. Please see settings in Admin->Edit Config, also Admin->Cron Info for more details');
    }
}
@set_time_limit(180);
// (180 seconds, 3 min max)
if (JB_CRON_EMULATION_ENABLED != 'YES') {
    JB_do_cron_job();
}