/** * Start user session. * * Note: This is intended to be called only from lib/setup.php! */ public static function start() { global $CFG, $DB; if (isset(self::$sessionactive)) { debugging('Session was already started!', DEBUG_DEVELOPER); return; } self::load_handler(); // Init the session handler only if everything initialised properly in lib/setup.php file // and the session is actually required. if (empty($DB) or empty($CFG->version) or !defined('NO_MOODLE_COOKIES') or NO_MOODLE_COOKIES or CLI_SCRIPT) { self::$sessionactive = false; self::init_empty_session(); return; } try { self::$handler->init(); self::prepare_cookies(); $newsid = empty($_COOKIE[session_name()]); self::$handler->start(); self::initialise_user_session($newsid); self::check_security(); } catch (\Exception $ex) { @session_write_close(); self::init_empty_session(); self::$sessionactive = false; throw $ex; } self::$sessionactive = true; }
/** * Start user session. * * Note: This is intended to be called only from lib/setup.php! */ public static function start() { global $CFG, $DB; if (isset(self::$sessionactive)) { debugging('Session was already started!', DEBUG_DEVELOPER); return; } self::load_handler(); // Init the session handler only if everything initialised properly in lib/setup.php file // and the session is actually required. if (empty($DB) or empty($CFG->version) or !defined('NO_MOODLE_COOKIES') or NO_MOODLE_COOKIES or CLI_SCRIPT) { self::$sessionactive = false; self::init_empty_session(); return; } try { self::$handler->init(); self::prepare_cookies(); $isnewsession = empty($_COOKIE[session_name()]); if (!self::$handler->start()) { // Could not successfully start/recover session. throw new \core\session\exception(get_string('servererror')); } self::initialise_user_session($isnewsession); self::check_security(); // Link global $USER and $SESSION, // this is tricky because PHP does not allow references to references // and global keyword uses internally once reference to the $GLOBALS array. // The solution is to use the $GLOBALS['USER'] and $GLOBALS['$SESSION'] // as the main storage of data and put references to $_SESSION. $GLOBALS['USER'] = $_SESSION['USER']; $_SESSION['USER'] =& $GLOBALS['USER']; $GLOBALS['SESSION'] = $_SESSION['SESSION']; $_SESSION['SESSION'] =& $GLOBALS['SESSION']; } catch (\Exception $ex) { self::init_empty_session(); self::$sessionactive = false; throw $ex; } self::$sessionactive = true; }
/** * Starts the session. * * @return bool success */ public function start() { $default = ini_get('max_execution_time'); set_time_limit($this->acquiretimeout); $result = parent::start(); set_time_limit($default); return $result; }
/** * Constructs the writer, optionally starts the handler * @param boolean $autostart set to true to autostart the handler * @return void */ public function __construct($autostart = true) { $this->handler = \PhpConsole\Handler::getInstance(); $this->connector = $this->handler->getConnector(); if ($autostart && !$this->handler->isStarted()) { $this->handler->start(); } }
/** * Start the session. * @return bool success */ public function start() { // NOTE: memcached <= 2.1.0 expires session locks automatically after max_execution_time, // this leads to major difference compared to other session drivers that timeout // and stop the second request execution instead. $default = ini_get('max_execution_time'); set_time_limit($this->acquiretimeout); $result = parent::start(); set_time_limit($default); return $result; }
/** * Start the session. * @return bool success */ public function start() { // NOTE: memcached before 2.2.0 expires session locks automatically after max_execution_time, // this leads to major difference compared to other session drivers that timeout // and stop the second request execution instead. $default = ini_get('max_execution_time'); set_time_limit($this->acquiretimeout); $isnewsession = empty($_COOKIE[session_name()]); $starttimer = microtime(true); $result = parent::start(); // If session_start returned TRUE, but it took as long // as the timeout value, and the $_SESSION returned is // empty when should not have been (isnewsession false) // then assume it did timeout and is invalid. // Add 1 second to elapsed time to account for inexact // timings in php_memcached_session.c. // @TODO Remove this check when php-memcached is fixed // to return false after key lock acquisition timeout. if (!$isnewsession && $result && count($_SESSION) == 0 && microtime(true) - $starttimer + 1 >= floatval($this->acquiretimeout)) { $result = false; } set_time_limit($default); return $result; }