public function gc() { global $AppUI; $max = $this->convertTime('max_lifetime'); $idle = $this->convertTime('idle_time'); // First pass is to kill any users that are logged in at the time of the session. $where = 'UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_updated) > ' . $idle . ' OR UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_created) > ' . $max; $q = new w2p_Database_Query(); $q->addTable('user_access_log'); $q->addUpdate('date_time_out', $q->dbfnNowWithTZ()); $q2 = new w2p_Database_Query(); $q2->addTable('sessions'); $q2->addQuery('session_user'); $q2->addWhere($where); $q->addWhere('user_access_log_id IN ( ' . $q2->prepare() . ' )'); $q->exec(); $q->clear(); $q2->clear(); // Now we simply delete the expired sessions. $q->setDelete('sessions'); $q->addWhere($where); $q->exec(); $q->clear(); if (w2PgetConfig('session_gc_scan_queue')) { // We need to scan the event queue. If $AppUI isn't created yet // And it isn't likely that it will be, we create it and run the // queue scanner. if (!isset($AppUI)) { $AppUI = new w2p_Core_CAppUI(); $queue = new w2p_System_EventQueue(); $queue->scan(); } } return true; }
<?php // Function to scan the event queue and execute any functions required. require_once 'base.php'; require_once W2P_BASE_DIR . '/includes/config.php'; require_once W2P_BASE_DIR . '/includes/main_functions.php'; require_once W2P_BASE_DIR . '/includes/db_adodb.php'; $defaultTZ = w2PgetConfig('system_timezone', 'UTC'); date_default_timezone_set($defaultTZ); $AppUI = new w2p_Core_CAppUI(); $AppUI->setUserLocale(); $queue = new w2p_System_EventQueue(); $queue->scan(); /* This is the first piece of a simple hook system to allow for regularly scheduled maintenance tasks to occur. This could be data validation and cleanup, sending email notifications, or workflow related tasks. */ $hooks = new w2p_System_HookHandler($AppUI); $hooks->process('cron');