Wikia code/includes/MemcachedSessions.php
Appearance
< Wikia code | includes
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. The information shown below refers to the now unmaintained 1.16 MediaWiki release. The current stable release number is 1.43.0. |
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\MemcachedSessions.php 2011-07-18 22:31:28.131836000 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\MemcachedSessions.php 2011-08-17 15:28:46.495117200 +0100
@@ -14,7 +14,7 @@
* @todo document
*/
function memsess_key( $id ) {
- return wfMemcKey( 'session', $id );
+ return wfGetSessionKey($id);
}
/**
@@ -37,8 +37,9 @@
* @todo document
*/
function memsess_read( $id ) {
- global $wgMemc;
- $data = $wgMemc->get( memsess_key( $id ) );
+ $memc =& getMemc();
+ $data = $memc->get( memsess_key( $id ) );
+
if(Â ! $data ) return '';
return $data;
}
@@ -47,8 +48,9 @@
* @todo document
*/
function memsess_write( $id, $data ) {
- global $wgMemc;
- $wgMemc->set( memsess_key( $id ), $data, 3600 );
+ $memc =& getMemc();
+ $memc->set( memsess_key( $id ), $data, 3600 );
+
return true;
}
@@ -56,8 +58,9 @@
* @todo document
*/
function memsess_destroy( $id ) {
- global $wgMemc;
- $wgMemc->delete( memsess_key( $id ) );
+ $memc =& getMemc();
+ $memc->delete( memsess_key( $id ) );
+
return true;
}
@@ -69,4 +72,31 @@
return true;
}
+/**
+ * getMemc
+ *
+ * get connection to memcached cluster
+ */
+function &getMemc() {
+ global $wgSessionMemCachedServers, $wgMemc, $wgSessionMemc;
+ global $wgMemCachedPersistent, $wgMemCachedDebug;
+
+ if( !empty( $wgSessionMemCachedServers ) && is_array( $wgSessionMemCachedServers ) && class_exists( 'MemcachedClientforWiki' ) ) {
+ if( !empty( $wgSessionMemc ) && is_object( $wgSessionMemc ) && $wgSessionMemc instanceof MemCachedClientforWiki ) {
+ return $wgSessionMemc;
+ }
+ else {
+ $wgSessionMemc = new MemCachedClientforWiki(
+ array( 'persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
+ $wgSessionMemc->set_servers( $wgSessionMemCachedServers );
+ $wgSessionMemc->set_debug( $wgMemCachedDebug );
+
+ return $wgSessionMemc;
+ }
+ }
+ else {
+ return $wgMemc;
+ }
+}
+
session_set_save_handler( 'memsess_open', 'memsess_close', 'memsess_read', 'memsess_write', 'memsess_destroy', 'memsess_gc' );