2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Session manager class.
21 * @copyright 2013 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core\session;
27 defined('MOODLE_INTERNAL') || die();
30 * Session manager, this is the public Moodle API for sessions.
32 * Following PHP functions MUST NOT be used directly:
33 * - session_start() - not necessary, lib/setup.php starts session automatically,
34 * use define('NO_MOODLE_COOKIE', true) if session not necessary.
35 * - session_write_close() - use \core\session\manager::write_close() instead.
36 * - session_destroy() - use require_logout() instead.
39 * @copyright 2013 Petr Skoda {@link http://skodak.org}
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 /** @var handler $handler active session handler instance */
44 protected static $handler;
46 /** @var bool $sessionactive Is the session active? */
47 protected static $sessionactive = null;
52 * Note: This is intended to be called only from lib/setup.php!
54 public static function start() {
57 if (isset(self::$sessionactive)) {
58 debugging('Session was already started!', DEBUG_DEVELOPER);
64 // Init the session handler only if everything initialised properly in lib/setup.php file
65 // and the session is actually required.
66 if (empty($DB) or empty($CFG->version) or !defined('NO_MOODLE_COOKIES') or NO_MOODLE_COOKIES or CLI_SCRIPT) {
67 self::$sessionactive = false;
68 self::init_empty_session();
73 self::$handler->init();
74 self::prepare_cookies();
75 $newsid = empty($_COOKIE[session_name()]);
77 self::$handler->start();
79 self::initialise_user_session($newsid);
80 self::check_security();
82 // Link global $USER and $SESSION,
83 // this is tricky because PHP does not allow references to references
84 // and global keyword uses internally once reference to the $GLOBALS array.
85 // The solution is to use the $GLOBALS['USER'] and $GLOBALS['$SESSION']
86 // as the main storage of data and put references to $_SESSION.
87 $GLOBALS['USER'] = $_SESSION['USER'];
88 $_SESSION['USER'] =& $GLOBALS['USER'];
89 $GLOBALS['SESSION'] = $_SESSION['SESSION'];
90 $_SESSION['SESSION'] =& $GLOBALS['SESSION'];
92 } catch (\Exception $ex) {
93 @session_write_close();
94 self::init_empty_session();
95 self::$sessionactive = false;
99 self::$sessionactive = true;
103 * Returns current page performance info.
105 * @return array perf info
107 public static function get_performance_info() {
112 self::load_handler();
113 $size = display_size(strlen(session_encode()));
114 $handler = get_class(self::$handler);
117 $info['size'] = $size;
118 $info['html'] = "<span class=\"sessionsize\">Session ($handler): $size</span> ";
119 $info['txt'] = "Session ($handler): $size ";
125 * Create handler instance.
127 protected static function load_handler() {
130 if (self::$handler) {
134 // Find out which handler to use.
136 $class = '\core\session\file';
138 } else if (!empty($CFG->session_handler_class)) {
139 $class = $CFG->session_handler_class;
141 } else if (!empty($CFG->dbsessions) and $DB->session_lock_supported()) {
142 $class = '\core\session\database';
145 $class = '\core\session\file';
147 self::$handler = new $class();
151 * Empty current session, fill it with not-logged-in user info.
153 * This is intended for installation scripts, unit tests and other
154 * special areas. Do NOT use for logout and session termination
155 * in normal requests!
157 public static function init_empty_session() {
160 // Backup notifications. These should be preserved across session changes until the user fetches and clears them.
162 if (isset($GLOBALS['SESSION']->notifications)) {
163 $notifications = $GLOBALS['SESSION']->notifications;
165 $GLOBALS['SESSION'] = new \stdClass();
167 $GLOBALS['USER'] = new \stdClass();
168 $GLOBALS['USER']->id = 0;
170 // Restore notifications.
171 $GLOBALS['SESSION']->notifications = $notifications;
172 if (isset($CFG->mnet_localhost_id)) {
173 $GLOBALS['USER']->mnethostid = $CFG->mnet_localhost_id;
175 // Not installed yet, the future host id will be most probably 1.
176 $GLOBALS['USER']->mnethostid = 1;
179 // Link global $USER and $SESSION.
181 $_SESSION['USER'] =& $GLOBALS['USER'];
182 $_SESSION['SESSION'] =& $GLOBALS['SESSION'];
186 * Make sure all cookie and session related stuff is configured properly before session start.
188 protected static function prepare_cookies() {
191 if (!isset($CFG->cookiesecure) or (!is_https() and empty($CFG->sslproxy))) {
192 $CFG->cookiesecure = 0;
195 if (!isset($CFG->cookiehttponly)) {
196 $CFG->cookiehttponly = 0;
199 // Set sessioncookie variable if it isn't already.
200 if (!isset($CFG->sessioncookie)) {
201 $CFG->sessioncookie = '';
203 $sessionname = 'MoodleSession'.$CFG->sessioncookie;
205 // Make sure cookie domain makes sense for this wwwroot.
206 if (!isset($CFG->sessioncookiedomain)) {
207 $CFG->sessioncookiedomain = '';
208 } else if ($CFG->sessioncookiedomain !== '') {
209 $host = parse_url($CFG->wwwroot, PHP_URL_HOST);
210 if ($CFG->sessioncookiedomain !== $host) {
211 if (substr($CFG->sessioncookiedomain, 0, 1) === '.') {
212 if (!preg_match('|^.*'.preg_quote($CFG->sessioncookiedomain, '|').'$|', $host)) {
213 // Invalid domain - it must be end part of host.
214 $CFG->sessioncookiedomain = '';
217 if (!preg_match('|^.*\.'.preg_quote($CFG->sessioncookiedomain, '|').'$|', $host)) {
218 // Invalid domain - it must be end part of host.
219 $CFG->sessioncookiedomain = '';
225 // Make sure the cookiepath is valid for this wwwroot or autodetect if not specified.
226 if (!isset($CFG->sessioncookiepath)) {
227 $CFG->sessioncookiepath = '';
229 if ($CFG->sessioncookiepath !== '/') {
230 $path = parse_url($CFG->wwwroot, PHP_URL_PATH).'/';
231 if ($CFG->sessioncookiepath === '') {
232 $CFG->sessioncookiepath = $path;
234 if (strpos($path, $CFG->sessioncookiepath) !== 0 or substr($CFG->sessioncookiepath, -1) !== '/') {
235 $CFG->sessioncookiepath = $path;
240 // Discard session ID from POST, GET and globals to tighten security,
241 // this is session fixation prevention.
242 unset($GLOBALS[$sessionname]);
243 unset($_GET[$sessionname]);
244 unset($_POST[$sessionname]);
245 unset($_REQUEST[$sessionname]);
247 // Compatibility hack for non-browser access to our web interface.
248 if (!empty($_COOKIE[$sessionname]) && $_COOKIE[$sessionname] == "deleted") {
249 unset($_COOKIE[$sessionname]);
252 // Set configuration.
253 session_name($sessionname);
254 session_set_cookie_params(0, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure, $CFG->cookiehttponly);
255 ini_set('session.use_trans_sid', '0');
256 ini_set('session.use_only_cookies', '1');
257 ini_set('session.hash_function', '0'); // For now MD5 - we do not have room for sha-1 in sessions table.
258 ini_set('session.use_strict_mode', '0'); // We have custom protection in session init.
259 ini_set('session.serialize_handler', 'php'); // We can move to 'php_serialize' after we require PHP 5.5.4 form Moodle.
261 // Moodle does normal session timeouts, this is for leftovers only.
262 ini_set('session.gc_probability', 1);
263 ini_set('session.gc_divisor', 1000);
264 ini_set('session.gc_maxlifetime', 60*60*24*4);
268 * Initialise $_SESSION, handles google access
269 * and sets up not-logged-in user properly.
271 * WARNING: $USER and $SESSION are set up later, do not use them yet!
273 * @param bool $newsid is this a new session in first http request?
275 protected static function initialise_user_session($newsid) {
280 // No session, very weird.
281 error_log('Missing session ID, session not started!');
282 self::init_empty_session();
286 if (!$record = $DB->get_record('sessions', array('sid'=>$sid), 'id, sid, state, userid, lastip, timecreated, timemodified')) {
288 if (!empty($_SESSION['USER']->id)) {
289 // This should not happen, just log it, we MUST not produce any output here!
290 error_log("Cannot find session record $sid for user ".$_SESSION['USER']->id.", creating new session.");
292 // Prevent session fixation attacks.
293 session_regenerate_id(true);
299 if (isset($_SESSION['USER']->id)) {
300 if (!empty($_SESSION['USER']->realuser)) {
301 $userid = $_SESSION['USER']->realuser;
303 $userid = $_SESSION['USER']->id;
306 // Verify timeout first.
307 $maxlifetime = $CFG->sessiontimeout;
309 if (isguestuser($userid) or empty($userid)) {
310 // Ignore guest and not-logged in timeouts, there is very little risk here.
313 } else if ($record->timemodified < time() - $maxlifetime) {
315 $authsequence = get_enabled_auth_plugins(); // Auths, in sequence.
316 foreach ($authsequence as $authname) {
317 $authplugin = get_auth_plugin($authname);
318 if ($authplugin->ignore_timeout_hook($_SESSION['USER'], $record->sid, $record->timecreated, $record->timemodified)) {
326 session_regenerate_id(true);
328 $DB->delete_records('sessions', array('id'=>$record->id));
331 // Update session tracking record.
333 $update = new \stdClass();
336 if ($record->userid != $userid) {
337 $update->userid = $record->userid = $userid;
341 $ip = getremoteaddr();
342 if ($record->lastip != $ip) {
343 $update->lastip = $record->lastip = $ip;
347 $updatefreq = empty($CFG->session_update_timemodified_frequency) ? 20 : $CFG->session_update_timemodified_frequency;
349 if ($record->timemodified == $record->timecreated) {
350 // Always do first update of existing record.
351 $update->timemodified = $record->timemodified = time();
354 } else if ($record->timemodified < time() - $updatefreq) {
355 // Update the session modified flag only once every 20 seconds.
356 $update->timemodified = $record->timemodified = time();
361 $update->id = $record->id;
362 $DB->update_record('sessions', $update);
369 // This happens when people switch session handlers...
370 session_regenerate_id(true);
372 $DB->delete_records('sessions', array('id'=>$record->id));
378 if (!isset($_SESSION['SESSION'])) {
379 $_SESSION['SESSION'] = new \stdClass();
387 if (!empty($CFG->opentogoogle)) {
388 if (\core_useragent::is_web_crawler()) {
389 $user = guest_user();
391 $referer = get_local_referer(false);
392 if (!empty($CFG->guestloginbutton) and !$user and !empty($referer)) {
393 // Automatically log in users coming from search engine results.
394 if (strpos($referer, 'google') !== false ) {
395 $user = guest_user();
396 } else if (strpos($referer, 'altavista') !== false ) {
397 $user = guest_user();
402 // Setup $USER and insert the session tracking record.
404 self::set_user($user);
405 self::add_session_record($user->id);
407 self::init_empty_session();
408 self::add_session_record(0);
412 $_SESSION['SESSION']->has_timed_out = true;
417 * Insert new empty session record.
419 * @return \stdClass the new record
421 protected static function add_session_record($userid) {
423 $record = new \stdClass();
425 $record->sid = session_id();
426 $record->sessdata = null;
427 $record->userid = $userid;
428 $record->timecreated = $record->timemodified = time();
429 $record->firstip = $record->lastip = getremoteaddr();
431 $record->id = $DB->insert_record('sessions', $record);
437 * Do various session security checks.
439 * WARNING: $USER and $SESSION are set up later, do not use them yet!
441 protected static function check_security() {
444 if (!empty($_SESSION['USER']->id) and !empty($CFG->tracksessionip)) {
445 // Make sure current IP matches the one for this session.
446 $remoteaddr = getremoteaddr();
448 if (empty($_SESSION['USER']->sessionip)) {
449 $_SESSION['USER']->sessionip = $remoteaddr;
452 if ($_SESSION['USER']->sessionip != $remoteaddr) {
453 // This is a security feature - terminate the session in case of any doubt.
454 self::terminate_current();
455 throw new exception('sessionipnomatch2', 'error');
461 * Login user, to be called from complete_user_login() only.
462 * @param \stdClass $user
464 public static function login_user(\stdClass $user) {
467 // Regenerate session id and delete old session,
468 // this helps prevent session fixation attacks from the same domain.
471 session_regenerate_id(true);
472 $DB->delete_records('sessions', array('sid'=>$sid));
473 self::add_session_record($user->id);
475 // Let enrol plugins deal with new enrolments if necessary.
476 enrol_check_plugins($user);
478 // Setup $USER object.
479 self::set_user($user);
483 * Terminate current user session.
486 public static function terminate_current() {
489 if (!self::$sessionactive) {
490 self::init_empty_session();
491 self::$sessionactive = false;
496 $DB->delete_records('external_tokens', array('sid'=>session_id(), 'tokentype'=>EXTERNAL_TOKEN_EMBEDDED));
497 } catch (\Exception $ignored) {
498 // Probably install/upgrade - ignore this problem.
501 // Initialize variable to pass-by-reference to headers_sent(&$file, &$line).
504 if (headers_sent($file, $line)) {
505 error_log('Cannot terminate session properly - headers were already sent in file: '.$file.' on line '.$line);
508 // Write new empty session and make sure the old one is deleted.
510 session_regenerate_id(true);
511 $DB->delete_records('sessions', array('sid'=>$sid));
512 self::init_empty_session();
513 self::add_session_record($_SESSION['USER']->id); // Do not use $USER here because it may not be set up yet.
514 session_write_close();
515 self::$sessionactive = false;
519 * No more changes in session expected.
520 * Unblocks the sessions, other scripts may start executing in parallel.
522 public static function write_close() {
523 if (self::$sessionactive) {
524 session_write_close();
527 @session_write_close();
530 self::$sessionactive = false;
534 * Does the PHP session with given id exist?
536 * The session must exist both in session table and actual
537 * session backend and the session must not be timed out.
539 * Timeout evaluation is simplified, the auth hooks are not executed.
544 public static function session_exists($sid) {
547 if (empty($CFG->version)) {
548 // Not installed yet, do not try to access database.
552 // Note: add sessions->state checking here if it gets implemented.
553 if (!$record = $DB->get_record('sessions', array('sid' => $sid), 'id, userid, timemodified')) {
557 if (empty($record->userid) or isguestuser($record->userid)) {
558 // Ignore guest and not-logged-in timeouts, there is very little risk here.
559 } else if ($record->timemodified < time() - $CFG->sessiontimeout) {
563 // There is no need the existence of handler storage in public API.
564 self::load_handler();
565 return self::$handler->session_exists($sid);
569 * Fake last access for given session, this prevents session timeout.
572 public static function touch_session($sid) {
575 // Timeouts depend on core sessions table only, no need to update anything in external stores.
577 $sql = "UPDATE {sessions} SET timemodified = :now WHERE sid = :sid";
578 $DB->execute($sql, array('now'=>time(), 'sid'=>$sid));
582 * Terminate all sessions unconditionally.
584 public static function kill_all_sessions() {
587 self::terminate_current();
589 self::load_handler();
590 self::$handler->kill_all_sessions();
593 $DB->delete_records('sessions');
594 } catch (\dml_exception $ignored) {
595 // Do not show any warnings - might be during upgrade/installation.
600 * Terminate give session unconditionally.
603 public static function kill_session($sid) {
606 self::load_handler();
608 if ($sid === session_id()) {
612 self::$handler->kill_session($sid);
614 $DB->delete_records('sessions', array('sid'=>$sid));
618 * Terminate all sessions of given user unconditionally.
620 * @param string $keepsid keep this sid if present
622 public static function kill_user_sessions($userid, $keepsid = null) {
625 $sessions = $DB->get_records('sessions', array('userid'=>$userid), 'id DESC', 'id, sid');
626 foreach ($sessions as $session) {
627 if ($keepsid and $keepsid === $session->sid) {
630 self::kill_session($session->sid);
635 * Terminate other sessions of current user depending
636 * on $CFG->limitconcurrentlogins restriction.
638 * This is expected to be called right after complete_user_login().
641 * * Do not use from SSO auth plugins, this would not work.
642 * * Do not use from web services because they do not have sessions.
645 * @param string $sid session id to be always keep, usually the current one
648 public static function apply_concurrent_login_limit($userid, $sid = null) {
651 // NOTE: the $sid parameter is here mainly to allow testing,
652 // in most cases it should be current session id.
654 if (isguestuser($userid) or empty($userid)) {
655 // This applies to real users only!
659 if (empty($CFG->limitconcurrentlogins) or $CFG->limitconcurrentlogins < 0) {
663 $count = $DB->count_records('sessions', array('userid' => $userid));
665 if ($count <= $CFG->limitconcurrentlogins) {
670 $select = "userid = :userid";
671 $params = array('userid' => $userid);
673 if ($DB->record_exists('sessions', array('sid' => $sid, 'userid' => $userid))) {
674 $select .= " AND sid <> :sid";
675 $params['sid'] = $sid;
680 $sessions = $DB->get_records_select('sessions', $select, $params, 'timecreated DESC', 'id, sid');
681 foreach ($sessions as $session) {
683 if ($i <= $CFG->limitconcurrentlogins) {
686 self::kill_session($session->sid);
693 * @param \stdClass $user record
695 public static function set_user(\stdClass $user) {
696 $GLOBALS['USER'] = $user;
697 unset($GLOBALS['USER']->description); // Conserve memory.
698 unset($GLOBALS['USER']->password); // Improve security.
699 if (isset($GLOBALS['USER']->lang)) {
700 // Make sure it is a valid lang pack name.
701 $GLOBALS['USER']->lang = clean_param($GLOBALS['USER']->lang, PARAM_LANG);
704 // Relink session with global $USER just in case it got unlinked somehow.
705 $_SESSION['USER'] =& $GLOBALS['USER'];
712 * Periodic timed-out session cleanup.
714 public static function gc() {
717 // This may take a long time...
718 \core_php_time_limit::raise();
720 $maxlifetime = $CFG->sessiontimeout;
723 // Kill all sessions of deleted and suspended users without any hesitation.
724 $rs = $DB->get_recordset_select('sessions', "userid IN (SELECT id FROM {user} WHERE deleted <> 0 OR suspended <> 0)", array(), 'id DESC', 'id, sid');
725 foreach ($rs as $session) {
726 self::kill_session($session->sid);
730 // Kill sessions of users with disabled plugins.
731 $auth_sequence = get_enabled_auth_plugins(true);
732 $auth_sequence = array_flip($auth_sequence);
733 unset($auth_sequence['nologin']); // No login means user cannot login.
734 $auth_sequence = array_flip($auth_sequence);
736 list($notplugins, $params) = $DB->get_in_or_equal($auth_sequence, SQL_PARAMS_QM, '', false);
737 $rs = $DB->get_recordset_select('sessions', "userid IN (SELECT id FROM {user} WHERE auth $notplugins)", $params, 'id DESC', 'id, sid');
738 foreach ($rs as $session) {
739 self::kill_session($session->sid);
743 // Now get a list of time-out candidates - real users only.
744 $sql = "SELECT u.*, s.sid, s.timecreated AS s_timecreated, s.timemodified AS s_timemodified
746 JOIN {sessions} s ON s.userid = u.id
747 WHERE s.timemodified < :purgebefore AND u.id <> :guestid";
748 $params = array('purgebefore' => (time() - $maxlifetime), 'guestid'=>$CFG->siteguest);
750 $authplugins = array();
751 foreach ($auth_sequence as $authname) {
752 $authplugins[$authname] = get_auth_plugin($authname);
754 $rs = $DB->get_recordset_sql($sql, $params);
755 foreach ($rs as $user) {
756 foreach ($authplugins as $authplugin) {
757 /** @var \auth_plugin_base $authplugin*/
758 if ($authplugin->ignore_timeout_hook($user, $user->sid, $user->s_timecreated, $user->s_timemodified)) {
762 self::kill_session($user->sid);
766 // Delete expired sessions for guest user account, give them larger timeout, there is no security risk here.
767 $params = array('purgebefore' => (time() - ($maxlifetime * 5)), 'guestid'=>$CFG->siteguest);
768 $rs = $DB->get_recordset_select('sessions', 'userid = :guestid AND timemodified < :purgebefore', $params, 'id DESC', 'id, sid');
769 foreach ($rs as $session) {
770 self::kill_session($session->sid);
774 // Delete expired sessions for userid = 0 (not logged in), better kill them asap to release memory.
775 $params = array('purgebefore' => (time() - $maxlifetime));
776 $rs = $DB->get_recordset_select('sessions', 'userid = 0 AND timemodified < :purgebefore', $params, 'id DESC', 'id, sid');
777 foreach ($rs as $session) {
778 self::kill_session($session->sid);
782 // Cleanup letfovers from the first browser access because it may set multiple cookies and then use only one.
783 $params = array('purgebefore' => (time() - 60*3));
784 $rs = $DB->get_recordset_select('sessions', 'userid = 0 AND timemodified = timecreated AND timemodified < :purgebefore', $params, 'id ASC', 'id, sid');
785 foreach ($rs as $session) {
786 self::kill_session($session->sid);
790 } catch (\Exception $ex) {
791 debugging('Error gc-ing sessions: '.$ex->getMessage(), DEBUG_NORMAL, $ex->getTrace());
796 * Is current $USER logged-in-as somebody else?
799 public static function is_loggedinas() {
800 return !empty($GLOBALS['USER']->realuser);
804 * Returns the $USER object ignoring current login-as session
805 * @return \stdClass user object
807 public static function get_realuser() {
808 if (self::is_loggedinas()) {
809 return $_SESSION['REALUSER'];
811 return $GLOBALS['USER'];
816 * Login as another user - no security checks here.
818 * @param \context $context
821 public static function loginas($userid, \context $context) {
824 if (self::is_loggedinas()) {
828 // Switch to fresh new $_SESSION.
830 $_SESSION['REALSESSION'] = clone($GLOBALS['SESSION']);
831 $GLOBALS['SESSION'] = new \stdClass();
832 $_SESSION['SESSION'] =& $GLOBALS['SESSION'];
834 // Create the new $USER object with all details and reload needed capabilities.
835 $_SESSION['REALUSER'] = clone($GLOBALS['USER']);
836 $user = get_complete_user_data('id', $userid);
837 $user->realuser = $_SESSION['REALUSER']->id;
838 $user->loginascontext = $context;
840 // Let enrol plugins deal with new enrolments if necessary.
841 enrol_check_plugins($user);
843 // Create event before $USER is updated.
844 $event = \core\event\user_loggedinas::create(
846 'objectid' => $USER->id,
847 'context' => $context,
848 'relateduserid' => $userid,
850 'originalusername' => fullname($USER, true),
851 'loggedinasusername' => fullname($user, true)
855 // Set up global $USER.
856 \core\session\manager::set_user($user);
861 * Add a JS session keepalive to the page.
863 * A JS session keepalive script will be called to update the session modification time every $frequency seconds.
865 * Upon failure, the specified error message will be shown to the user.
867 * @param string $identifier The string identifier for the message to show on failure.
868 * @param string $component The string component for the message to show on failure.
869 * @param int $frequency The update frequency in seconds.
870 * @throws coding_exception IF the frequency is longer than the session lifetime.
872 public static function keepalive($identifier = 'sessionerroruser', $component = 'error', $frequency = null) {
876 if ($frequency > $CFG->sessiontimeout) {
877 // Sanity check the frequency.
878 throw new \coding_exception('Keepalive frequency is longer than the session lifespan.');
881 // A frequency of sessiontimeout / 3 allows for one missed request whilst still preserving the session.
882 $frequency = $CFG->sessiontimeout / 3;
885 // Add the session keepalive script to the list of page output requirements.
886 $sessionkeepaliveurl = new \moodle_url('/lib/sessionkeepalive_ajax.php');
887 $PAGE->requires->string_for_js($identifier, $component);
888 $PAGE->requires->yui_module('moodle-core-checknet', 'M.core.checknet.init', array(array(
889 // The JS config takes this is milliseconds rather than seconds.
890 'frequency' => $frequency * 1000,
891 'message' => array($identifier, $component),
892 'uri' => $sessionkeepaliveurl->out(),