MediaWiki  REL1_24
ObjectCacheSessionHandler.php
Go to the documentation of this file.
00001 <?php
00030 class ObjectCacheSessionHandler {
00034     static function install() {
00035         session_set_save_handler(
00036             array( __CLASS__, 'open' ),
00037             array( __CLASS__, 'close' ),
00038             array( __CLASS__, 'read' ),
00039             array( __CLASS__, 'write' ),
00040             array( __CLASS__, 'destroy' ),
00041             array( __CLASS__, 'gc' ) );
00042 
00043         // It's necessary to register a shutdown function to call session_write_close(),
00044         // because by the time the request shutdown function for the session module is
00045         // called, $wgMemc has already been destroyed. Shutdown functions registered
00046         // this way are called before object destruction.
00047         register_shutdown_function( array( __CLASS__, 'handleShutdown' ) );
00048     }
00049 
00054     static function getCache() {
00055         global $wgSessionCacheType;
00056         return ObjectCache::getInstance( $wgSessionCacheType );
00057     }
00058 
00065     static function getKey( $id ) {
00066         return wfMemcKey( 'session', $id );
00067     }
00068 
00076     static function open( $save_path, $session_name ) {
00077         return true;
00078     }
00079 
00086     static function close() {
00087         return true;
00088     }
00089 
00096     static function read( $id ) {
00097         $data = self::getCache()->get( self::getKey( $id ) );
00098         if ( $data === false ) {
00099             return '';
00100         }
00101         return $data;
00102     }
00103 
00111     static function write( $id, $data ) {
00112         global $wgObjectCacheSessionExpiry;
00113         self::getCache()->set( self::getKey( $id ), $data, $wgObjectCacheSessionExpiry );
00114         return true;
00115     }
00116 
00123     static function destroy( $id ) {
00124         self::getCache()->delete( self::getKey( $id ) );
00125         return true;
00126     }
00127 
00135     static function gc( $maxlifetime ) {
00136         return true;
00137     }
00138 
00143     static function handleShutdown() {
00144         session_write_close();
00145     }
00146 }