1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
<?php
/**
* This file gets included if $wgSessionsInMemcache is set in the config.
* It redirects session handling functions to store their data in memcached
* instead of the local filesystem. Depending on circumstances, it may also
* be necessary to change the cookie settings to work across hostnames.
* See: http://www.php.net/manual/en/function.session-set-save-handler.php
*
* @file
* @ingroup Cache
*/
/**
* Get a cache key for the given session id.
*
* @param $id String: session id
* @return String: cache key
*/
function memsess_key( $id ) {
return wfMemcKey( 'session', $id );
}
/**
* Callback when opening a session.
* NOP: $wgMemc should be set up already.
*
* @param $save_path String: path used to store session files, unused
* @param $session_name String: session name
* @return Boolean: success
*/
function memsess_open( $save_path, $session_name ) {
return true;
}
/**
* Callback when closing a session.
* NOP.
*
* @return Boolean: success
*/
function memsess_close() {
return true;
}
/**
* Callback when reading session data.
*
* @param $id String: session id
* @return Mixed: session data
*/
function memsess_read( $id ) {
global $wgMemc;
$data = $wgMemc->get( memsess_key( $id ) );
if( ! $data ) return '';
return $data;
}
/**
* Callback when writing session data.
*
* @param $id String: session id
* @param $data Mixed: session data
* @return Boolean: success
*/
function memsess_write( $id, $data ) {
global $wgMemc;
$wgMemc->set( memsess_key( $id ), $data, 3600 );
return true;
}
/**
* Callback to destroy a session when calling session_destroy().
*
* @param $id String: session id
* @return Boolean: success
*/
function memsess_destroy( $id ) {
global $wgMemc;
$wgMemc->delete( memsess_key( $id ) );
return true;
}
/**
* Callback to execute garbage collection.
* NOP: Memcached performs garbage collection.
*
* @param $maxlifetime Integer: maximum session life time
* @return Boolean: success
*/
function memsess_gc( $maxlifetime ) {
return true;
}
function memsess_write_close() {
session_write_close();
}
|