/** * Install a session handler for the current web request * @param SessionManager $manager */ public static function install(SessionManager $manager) { if (self::$instance) { $manager->setupPHPSessionHandler(self::$instance); return; } self::$instance = new self($manager); // Close any auto-started session, before we replace it session_write_close(); // Tell PHP not to mess with cookies itself ini_set('session.use_cookies', 0); ini_set('session.use_trans_sid', 0); // Also set a sane serialization handler \Wikimedia\PhpSessionSerializer::setSerializeHandler(); session_set_save_handler(array(self::$instance, 'open'), array(self::$instance, 'close'), array(self::$instance, 'read'), array(self::$instance, 'write'), array(self::$instance, 'destroy'), array(self::$instance, 'gc')); // It's necessary to register a shutdown function to call session_write_close(), // because by the time the request shutdown function for the session module is // called, other needed objects may have already been destroyed. Shutdown functions // registered this way are called before object destruction. register_shutdown_function(array(self::$instance, 'handleShutdown')); }
/** * Install a session handler for the current web request * @param SessionManager $manager */ public static function install(SessionManager $manager) { if (self::$instance) { $manager->setupPHPSessionHandler(self::$instance); return; } // @codeCoverageIgnoreStart if (defined('MW_NO_SESSION_HANDLER')) { throw new \BadMethodCallException('MW_NO_SESSION_HANDLER is defined'); } // @codeCoverageIgnoreEnd self::$instance = new self($manager); // Close any auto-started session, before we replace it session_write_close(); // Tell PHP not to mess with cookies itself ini_set('session.use_cookies', 0); ini_set('session.use_trans_sid', 0); // T124510: Disable automatic PHP session related cache headers. // MediaWiki adds it's own headers and the default PHP behavior may // set headers such as 'Pragma: no-cache' that cause problems with // some user agents. session_cache_limiter(''); // Also set a sane serialization handler \Wikimedia\PhpSessionSerializer::setSerializeHandler(); // Register this as the save handler, and register an appropriate // shutdown function. session_set_save_handler(self::$instance, true); }