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