You are here

README.txt in Session Proxy 7

Session Proxy
=============

Session proxy is not a module: it is a replacement for Drupal core session
handling API.

It acts as a proxy between fixed core procedural API towards a fully object
oriented, more flexible and easier to extend session management API.

Basically, it strongly encapsulate the original API, separating user management
against raw session storage: by using it you are able to implement any session
storage engine (memcache, redis, ... ) without handling cookies and by users
yourself.

Provided session engines
------------------------

It ships three different session managing implementations:

 1. Database session handling: core default, ported to the object oriented
    API. It comes with an additional SQL query done more than core session.inc
    default implementation due to the API strong encapsulation.

 2. Native PHP session handling: by selecting this session management mode,
    you explicitely remove any core session management, and let PHP manage
    it. This can be useful if you intend to use low-level PHP extensions,
    such as Memcache or PhpRedis to handle session in PHP low-level layer
    instead of core. This allow to use any PHP native session storage to
    work gracefully: some of them are high performance.

 3. Cache based storage engine: Using the same session handling than core,
    but deporting raw session storage into a cache backend instance. You can
    use any already-functionning cache backend to store sessions. Sessions
    will use their own bin, and won't be cleared at cache clear all time.

Installation and configuration
------------------------------

If you intend to use the Drupal default cache implementation (database cache)
for session handling, you need to enable and install the "session_proxy" module
to ensure the database table (bin) for the sessions storage cache backend will
be created. For all other cases, this is unnecessary. 

All configuration will reside into your settings.php file, see the documented
example below for details:

// -- Database backend, session management by Drupal ---------
//
//  This is the classical way to handle sessions in Drupal
// Actually no session locking applied in Drupal so race conditions on session
// write operations (for the same user/session) can happen.
    // Replace core session management with Session Proxy API.
$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // If you set this to TRUE, session management will be PHP native session
    // management and not Drupal session management (which is database sessions
    // in classical Drupal installations).
    // By doing this, all other parameters below will be ignored.
    // by using native session management you'll reactivate the PHP native
    // session locking management, that means session_start() can only be done 
    // for one HTTP request in the same time (no parallel load of images for
    // imagecache images, no parallel browser tabs, auto-serialization of 
    // requests which belongs to the same session)
$conf['session_storage_force_default'] = FALSE;

    // PHP class to use as session storage engine. Default is the database
    // implementation (port of the actual core session management). By setting
    // this parameter, all others settings except 'session_storage_force_default'
    // or 'session_storage_options' will be ignored.
$conf['session_storage_class'] = 'SessionProxy_Storage_Database';

// -- APC backend & session managment by drupal ---------
//
// (use it only if you have only one server)
// WARNING: be careful with APC backend for sessions, when the cache is full
// it perform an automatic cache clear, same thing with apache reload
// and that mean you may loose your sessions, so use with extreme care
// Actually no session locking applied in Drupal so race conditions on session
// write operations (for the same user/session) can happen (like in default 
// Drupal sessions).
    // Replace core session management with Session Proxy API.
//$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // do not forget to empty the sessions table in Drupal, not used anymore
    //
    // If you set this to TRUE, session management will be PHP native session
    // management. By doing this, all other parameters below will be ignored.
$conf['session_storage_force_default'] = FALSE;

    // PHP class to use as session storage engine.
    // we use the 'Cache' storage backend to use Drupal7 cache backends
    // (or the same with Drupal6 & cache_backport module)'
$conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
    // Everything into 'session_storage_options' are arbitrary key value pairs,
    // each storage backend will define its own keys.
    // For cache backend, the only mandatory one is the class name that to use
    // as cache backend. This class must implement DrupalCacheInterface. If you
    // do not set this class 'DrupalDatabaseCache' will be used. 
$conf['session_storage_options']['cache_backend'] = 'DrupalAPCCache';
// if you do not have already configured APC as a cache backend do it there
//$conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc';
//$conf['apc_show_debug'] = FALSE;

// -- Memcache backend & session managment by drupal --
//
// certainly a very fast thing, 
// Actually no session locking applied in Drupal so race conditions on session
// write operations (for the same user/session) can happen (like in default 
// Drupal sessions).
    // Replace core session management with Session Proxy API.
//$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // do not forget to empty the sessions table in Drupal, not used anymore
    //
    // If you set this to TRUE, session management will be PHP native session
    // management. By doing this, all other parameters below will be ignored.
$conf['session_storage_force_default'] = FALSE;

    // PHP class to use as session storage engine.
    // we use the 'Cache' storage backend to use Drupal7 cache backends
    // (or the same with Drupal6 & cache_backport module)'
$conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
    // Everything into 'session_storage_options' are arbitrary key value pairs,
    // each storage backend will define its own keys.
    // For cache backend, the only mandatory one is the class name that to use
    // as cache backend. This class must implement DrupalCacheInterface. If you
    // do not set this class 'DrupalDatabaseCache' will be used. 
$conf['session_storage_options']['cache_backend'] = 'MemCacheDrupal';
    // if you do not have already configured APC as a cache backend do it there
    // $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
    // see configuration of 'MemCacheDrupal' for details 
    // (in cache_backport module's README.txt or in the module README.txt)

// ---- Memcache session managment by PHP ----
//
// Here the session proxy module does a very minimum amount of things
// all is done by your PHP configuration
// If you want session locking mechanism you'll need a version > 3.0.4 of the
// memcache-php library. Without that some race conditions on parallel requests
// (ajax, and such) may happen. With it you'll serialize same session executions
// and may experiment some performance loss.
// to get a version > 3 while it's unstable do a "pecl install memcache-beta "
//php-memcache ----
// INI settings
//session.save_handler = memcache
//session.save_path = "tcp://127.0.0.1:11211" 
//memcache.lock_timeout = 15 // memcache-php > 3.0.4, else no locks for sessions
//php-memcached (untested) ---
// INI settings
//session.save_handler = memcached
//session.save_path = "127.0.0.1:11211"
// and this for php-memcached would stay here and not in ini settings
//$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_ATTEMPTS]=30;
//$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_WAIT]=100000;
//$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_EXPIRATION]=30;
    // Replace core session management with Session Proxy API.
$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // do not forget to empty the sessions table in Drupal, not used anymore
    //
    // If you set this to TRUE, session management will be PHP native session
    // management. By doing this, all other parameters below will be ignored.
$conf['session_storage_force_default'] = TRUE;

// ---- File cache Backend, session managment by Drupal ----
// back to files like in native PHP implementation, but without session locking
// and with a write delay, so may be quite really faster
// Actually no session locking applied in Drupal so race conditions on session
// write operations (for the same user/session) can happen (like in default 
// Drupal sessions).
    // Replace core session management with Session Proxy API.
$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // do not forget to empty the sessions table in Drupal, not used anymore
    //
    // If you set this to TRUE, session management will be PHP native session
    // management. By doing this, all other parameters below will be ignored.
$conf['session_storage_force_default'] = FALSE;

    // PHP class to use as session storage engine.
    // we use the 'Cache' storage backend to use Drupal7 cache backends
    // (or the same with Drupal6 & cache_backport module)'
$conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
    // Everything into 'session_storage_options' are arbitrary key value pairs,
    // each storage backend will define its own keys.
    // For cache backend, the only mandatory one is the class name that to use
    // as cache backend. This class must implement DrupalCacheInterface. If you
    // do not set this class 'DrupalDatabaseCache' will be used. 
$conf['session_storage_options']['cache_backend'] = 'DrupalFileCache';
    // if you do not have already configured APC as a cache backend do it there
    // $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
    // see configuration of 'MemCacheDrupal' for details 
    // (in cache_backport module's README.txt or in the module README.txt)
    // $conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
    // $conf['filecache_fast_pagecache'] = TRUE; // set TRUE to enable fast page serving
    // $conf['filecache_directory'] = $conf['file_directory_temp'] . '/filecache';

// ---- Redis cache Backend, session managment by Drupal ----
//
// Here is an example of usage the cache storage engine, using the Redis
// module for storing sessions.
// Actually no session locking applied in Drupal so race conditions on session
// write operations (for the same user/session) can happen (like in default 
// Drupal sessions).
    // Replace core session management with Session Proxy API.
$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
    //
    // do not forget to empty the sessions table in Drupal, not used anymore
    //
    // If you set this to TRUE, session management will be PHP native session
    // management. By doing this, all other parameters below will be ignored.
$conf['session_storage_force_default'] = FALSE;

    // PHP class to use as session storage engine.
    // we use the 'Cache' storage backend to use Drupal7 cache backends
    // (or the same with Drupal6 & cache_backport module)'
$conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
    // Everything into 'session_storage_options' are arbitrary key value pairs,
    // each storage backend will define its own keys.
    // For cache backend, the only mandatory one is the class name that to use
    // as cache backend. This class must implement DrupalCacheInterface. If you
    // do not set this class 'DrupalDatabaseCache' will be used. 
$conf['session_storage_options']['cache_backend'] = 'Redis_Cache';
    // Tell Drupal to load the Redis backend properly (if not done previously in
    // settings), see the Redis module documentation for details about this.
    //$conf['cache_backends'][] = 'sites/all/modules/redis/redis.autoload.inc';
    //$conf['redis_client_interface'] = 'PhpRedis';

Session Locks
--------------
Native PHP file implementation of sessions prevents race conditions with
parallel requests from the same session by locking on session_start(), so every 
parallel session gets serialized.

Drupal 7 implementation of the session in the database allows parallel
executions with the caveat of overriding the session content with the content
of the last-to-end parallel query. Drupal also reduces the number of write
requests by delaying the session write at the end of the request.

Actually all sessions managed by Drupal or this session proxy module can have
the same race condition as the default Drupal installation. But with this module
you can use 'session_storage_force_default' setting to get the native PHP
implementation or the memcache-native implementation of the sessions 
(http://php.net/manual/en/memcached.sessions.php) and have the session locks.

Notes
-----

If you download and properly install the Autoloader Early module, you may
experience better autoloading performances. You can download it at:

  http://drupal.org/project/autoloaderearly

Some cache backend links:

  * Redis - http://drupal.org/project/redis

  * Memcache API and Integration - http://drupal.org/project/memcache
  
Cache Backport : 

If you want to use the (near to come) Drupal6 version of this module you will
need the Cache Backport module and the Drupal7 versions of the backends.
  * Cache Backport : http://drupal.org/project/cache_backport

File

README.txt
View source
  1. Session Proxy
  2. =============
  3. Session proxy is not a module: it is a replacement for Drupal core session
  4. handling API.
  5. It acts as a proxy between fixed core procedural API towards a fully object
  6. oriented, more flexible and easier to extend session management API.
  7. Basically, it strongly encapsulate the original API, separating user management
  8. against raw session storage: by using it you are able to implement any session
  9. storage engine (memcache, redis, ... ) without handling cookies and by users
  10. yourself.
  11. Provided session engines
  12. ------------------------
  13. It ships three different session managing implementations:
  14. 1. Database session handling: core default, ported to the object oriented
  15. API. It comes with an additional SQL query done more than core session.inc
  16. default implementation due to the API strong encapsulation.
  17. 2. Native PHP session handling: by selecting this session management mode,
  18. you explicitely remove any core session management, and let PHP manage
  19. it. This can be useful if you intend to use low-level PHP extensions,
  20. such as Memcache or PhpRedis to handle session in PHP low-level layer
  21. instead of core. This allow to use any PHP native session storage to
  22. work gracefully: some of them are high performance.
  23. 3. Cache based storage engine: Using the same session handling than core,
  24. but deporting raw session storage into a cache backend instance. You can
  25. use any already-functionning cache backend to store sessions. Sessions
  26. will use their own bin, and won't be cleared at cache clear all time.
  27. Installation and configuration
  28. ------------------------------
  29. If you intend to use the Drupal default cache implementation (database cache)
  30. for session handling, you need to enable and install the "session_proxy" module
  31. to ensure the database table (bin) for the sessions storage cache backend will
  32. be created. For all other cases, this is unnecessary.
  33. All configuration will reside into your settings.php file, see the documented
  34. example below for details:
  35. // -- Database backend, session management by Drupal ---------
  36. //
  37. // This is the classical way to handle sessions in Drupal
  38. // Actually no session locking applied in Drupal so race conditions on session
  39. // write operations (for the same user/session) can happen.
  40. // Replace core session management with Session Proxy API.
  41. $conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  42. //
  43. // If you set this to TRUE, session management will be PHP native session
  44. // management and not Drupal session management (which is database sessions
  45. // in classical Drupal installations).
  46. // By doing this, all other parameters below will be ignored.
  47. // by using native session management you'll reactivate the PHP native
  48. // session locking management, that means session_start() can only be done
  49. // for one HTTP request in the same time (no parallel load of images for
  50. // imagecache images, no parallel browser tabs, auto-serialization of
  51. // requests which belongs to the same session)
  52. $conf['session_storage_force_default'] = FALSE;
  53. // PHP class to use as session storage engine. Default is the database
  54. // implementation (port of the actual core session management). By setting
  55. // this parameter, all others settings except 'session_storage_force_default'
  56. // or 'session_storage_options' will be ignored.
  57. $conf['session_storage_class'] = 'SessionProxy_Storage_Database';
  58. // -- APC backend & session managment by drupal ---------
  59. //
  60. // (use it only if you have only one server)
  61. // WARNING: be careful with APC backend for sessions, when the cache is full
  62. // it perform an automatic cache clear, same thing with apache reload
  63. // and that mean you may loose your sessions, so use with extreme care
  64. // Actually no session locking applied in Drupal so race conditions on session
  65. // write operations (for the same user/session) can happen (like in default
  66. // Drupal sessions).
  67. // Replace core session management with Session Proxy API.
  68. //$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  69. //
  70. // do not forget to empty the sessions table in Drupal, not used anymore
  71. //
  72. // If you set this to TRUE, session management will be PHP native session
  73. // management. By doing this, all other parameters below will be ignored.
  74. $conf['session_storage_force_default'] = FALSE;
  75. // PHP class to use as session storage engine.
  76. // we use the 'Cache' storage backend to use Drupal7 cache backends
  77. // (or the same with Drupal6 & cache_backport module)'
  78. $conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
  79. // Everything into 'session_storage_options' are arbitrary key value pairs,
  80. // each storage backend will define its own keys.
  81. // For cache backend, the only mandatory one is the class name that to use
  82. // as cache backend. This class must implement DrupalCacheInterface. If you
  83. // do not set this class 'DrupalDatabaseCache' will be used.
  84. $conf['session_storage_options']['cache_backend'] = 'DrupalAPCCache';
  85. // if you do not have already configured APC as a cache backend do it there
  86. //$conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc';
  87. //$conf['apc_show_debug'] = FALSE;
  88. // -- Memcache backend & session managment by drupal --
  89. //
  90. // certainly a very fast thing,
  91. // Actually no session locking applied in Drupal so race conditions on session
  92. // write operations (for the same user/session) can happen (like in default
  93. // Drupal sessions).
  94. // Replace core session management with Session Proxy API.
  95. //$conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  96. //
  97. // do not forget to empty the sessions table in Drupal, not used anymore
  98. //
  99. // If you set this to TRUE, session management will be PHP native session
  100. // management. By doing this, all other parameters below will be ignored.
  101. $conf['session_storage_force_default'] = FALSE;
  102. // PHP class to use as session storage engine.
  103. // we use the 'Cache' storage backend to use Drupal7 cache backends
  104. // (or the same with Drupal6 & cache_backport module)'
  105. $conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
  106. // Everything into 'session_storage_options' are arbitrary key value pairs,
  107. // each storage backend will define its own keys.
  108. // For cache backend, the only mandatory one is the class name that to use
  109. // as cache backend. This class must implement DrupalCacheInterface. If you
  110. // do not set this class 'DrupalDatabaseCache' will be used.
  111. $conf['session_storage_options']['cache_backend'] = 'MemCacheDrupal';
  112. // if you do not have already configured APC as a cache backend do it there
  113. // $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  114. // see configuration of 'MemCacheDrupal' for details
  115. // (in cache_backport module's README.txt or in the module README.txt)
  116. // ---- Memcache session managment by PHP ----
  117. //
  118. // Here the session proxy module does a very minimum amount of things
  119. // all is done by your PHP configuration
  120. // If you want session locking mechanism you'll need a version > 3.0.4 of the
  121. // memcache-php library. Without that some race conditions on parallel requests
  122. // (ajax, and such) may happen. With it you'll serialize same session executions
  123. // and may experiment some performance loss.
  124. // to get a version > 3 while it's unstable do a "pecl install memcache-beta "
  125. //php-memcache ----
  126. // INI settings
  127. //session.save_handler = memcache
  128. //session.save_path = "tcp://127.0.0.1:11211"
  129. //memcache.lock_timeout = 15 // memcache-php > 3.0.4, else no locks for sessions
  130. //php-memcached (untested) ---
  131. // INI settings
  132. //session.save_handler = memcached
  133. //session.save_path = "127.0.0.1:11211"
  134. // and this for php-memcached would stay here and not in ini settings
  135. //$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_ATTEMPTS]=30;
  136. //$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_WAIT]=100000;
  137. //$conf['memcache_options'][Memcached::MEMC_SESS_LOCK_EXPIRATION]=30;
  138. // Replace core session management with Session Proxy API.
  139. $conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  140. //
  141. // do not forget to empty the sessions table in Drupal, not used anymore
  142. //
  143. // If you set this to TRUE, session management will be PHP native session
  144. // management. By doing this, all other parameters below will be ignored.
  145. $conf['session_storage_force_default'] = TRUE;
  146. // ---- File cache Backend, session managment by Drupal ----
  147. // back to files like in native PHP implementation, but without session locking
  148. // and with a write delay, so may be quite really faster
  149. // Actually no session locking applied in Drupal so race conditions on session
  150. // write operations (for the same user/session) can happen (like in default
  151. // Drupal sessions).
  152. // Replace core session management with Session Proxy API.
  153. $conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  154. //
  155. // do not forget to empty the sessions table in Drupal, not used anymore
  156. //
  157. // If you set this to TRUE, session management will be PHP native session
  158. // management. By doing this, all other parameters below will be ignored.
  159. $conf['session_storage_force_default'] = FALSE;
  160. // PHP class to use as session storage engine.
  161. // we use the 'Cache' storage backend to use Drupal7 cache backends
  162. // (or the same with Drupal6 & cache_backport module)'
  163. $conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
  164. // Everything into 'session_storage_options' are arbitrary key value pairs,
  165. // each storage backend will define its own keys.
  166. // For cache backend, the only mandatory one is the class name that to use
  167. // as cache backend. This class must implement DrupalCacheInterface. If you
  168. // do not set this class 'DrupalDatabaseCache' will be used.
  169. $conf['session_storage_options']['cache_backend'] = 'DrupalFileCache';
  170. // if you do not have already configured APC as a cache backend do it there
  171. // $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
  172. // see configuration of 'MemCacheDrupal' for details
  173. // (in cache_backport module's README.txt or in the module README.txt)
  174. // $conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
  175. // $conf['filecache_fast_pagecache'] = TRUE; // set TRUE to enable fast page serving
  176. // $conf['filecache_directory'] = $conf['file_directory_temp'] . '/filecache';
  177. // ---- Redis cache Backend, session managment by Drupal ----
  178. //
  179. // Here is an example of usage the cache storage engine, using the Redis
  180. // module for storing sessions.
  181. // Actually no session locking applied in Drupal so race conditions on session
  182. // write operations (for the same user/session) can happen (like in default
  183. // Drupal sessions).
  184. // Replace core session management with Session Proxy API.
  185. $conf['session_inc'] = 'sites/all/modules/session_proxy/session.inc';
  186. //
  187. // do not forget to empty the sessions table in Drupal, not used anymore
  188. //
  189. // If you set this to TRUE, session management will be PHP native session
  190. // management. By doing this, all other parameters below will be ignored.
  191. $conf['session_storage_force_default'] = FALSE;
  192. // PHP class to use as session storage engine.
  193. // we use the 'Cache' storage backend to use Drupal7 cache backends
  194. // (or the same with Drupal6 & cache_backport module)'
  195. $conf['session_storage_class'] = 'SessionProxy_Storage_Cache';
  196. // Everything into 'session_storage_options' are arbitrary key value pairs,
  197. // each storage backend will define its own keys.
  198. // For cache backend, the only mandatory one is the class name that to use
  199. // as cache backend. This class must implement DrupalCacheInterface. If you
  200. // do not set this class 'DrupalDatabaseCache' will be used.
  201. $conf['session_storage_options']['cache_backend'] = 'Redis_Cache';
  202. // Tell Drupal to load the Redis backend properly (if not done previously in
  203. // settings), see the Redis module documentation for details about this.
  204. //$conf['cache_backends'][] = 'sites/all/modules/redis/redis.autoload.inc';
  205. //$conf['redis_client_interface'] = 'PhpRedis';
  206. Session Locks
  207. --------------
  208. Native PHP file implementation of sessions prevents race conditions with
  209. parallel requests from the same session by locking on session_start(), so every
  210. parallel session gets serialized.
  211. Drupal 7 implementation of the session in the database allows parallel
  212. executions with the caveat of overriding the session content with the content
  213. of the last-to-end parallel query. Drupal also reduces the number of write
  214. requests by delaying the session write at the end of the request.
  215. Actually all sessions managed by Drupal or this session proxy module can have
  216. the same race condition as the default Drupal installation. But with this module
  217. you can use 'session_storage_force_default' setting to get the native PHP
  218. implementation or the memcache-native implementation of the sessions
  219. (http://php.net/manual/en/memcached.sessions.php) and have the session locks.
  220. Notes
  221. -----
  222. If you download and properly install the Autoloader Early module, you may
  223. experience better autoloading performances. You can download it at:
  224. http://drupal.org/project/autoloaderearly
  225. Some cache backend links:
  226. * Redis - http://drupal.org/project/redis
  227. * Memcache API and Integration - http://drupal.org/project/memcache
  228. Cache Backport :
  229. If you want to use the (near to come) Drupal6 version of this module you will
  230. need the Cache Backport module and the Drupal7 versions of the backends.
  231. * Cache Backport : http://drupal.org/project/cache_backport