MemcachedSessions.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * @todo document
  14. */
  15. function memsess_key( $id ) {
  16. return wfMemcKey( 'session', $id );
  17. }
  18. /**
  19. * @todo document
  20. */
  21. function memsess_open( $save_path, $session_name ) {
  22. # NOP, $wgMemc should be set up already
  23. return true;
  24. }
  25. /**
  26. * @todo document
  27. */
  28. function memsess_close() {
  29. # NOP
  30. return true;
  31. }
  32. /**
  33. * @todo document
  34. */
  35. function memsess_read( $id ) {
  36. global $wgMemc;
  37. $data = $wgMemc->get( memsess_key( $id ) );
  38. if( ! $data ) return '';
  39. return $data;
  40. }
  41. /**
  42. * @todo document
  43. */
  44. function memsess_write( $id, $data ) {
  45. global $wgMemc;
  46. $wgMemc->set( memsess_key( $id ), $data, 3600 );
  47. return true;
  48. }
  49. /**
  50. * @todo document
  51. */
  52. function memsess_destroy( $id ) {
  53. global $wgMemc;
  54. $wgMemc->delete( memsess_key( $id ) );
  55. return true;
  56. }
  57. /**
  58. * @todo document
  59. */
  60. function memsess_gc( $maxlifetime ) {
  61. # NOP: Memcached performs garbage collection.
  62. return true;
  63. }
  64. session_set_save_handler( 'memsess_open', 'memsess_close', 'memsess_read', 'memsess_write', 'memsess_destroy', 'memsess_gc' );