Advertisement
Guest User

Untitled

a guest
Feb 14th, 2011
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. // Sasha Dolgy <sasha.dolgy gmail>
  4. // Twitter: @sdolgy
  5. // using phpcassa:  https://github.com/thobbs/phpcassa
  6. $ROOT = '/path/to/phpcassa';
  7.  
  8. require_once($GLOBALS['ROOT'] . '/include/connection.php');
  9. require_once($GLOBALS['ROOT'] . '/include/columnfamily.php');
  10.  
  11. // helper function i use elsewhere
  12. function add_record($cf, $key, $cols, $expiry=null) {
  13.  
  14.     if ($cf != null && $key != null && isset($cols)) {
  15.         $conn = getConn();
  16.         $target_cf = new ColumnFamily(getConn(), $cf);
  17.         if ($expiry == null) { $target_cf->insert($key, $cols, null); }
  18.         else { $target_cf->insert($key, $cols, null, $ttl=$expiry); }
  19.     } else {
  20.         echo "null information for add_record";
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. function open($session_name)
  27. {
  28.   return(true);
  29. }
  30.  
  31. function close()
  32. {
  33.   return(true);
  34. }
  35.  
  36. function read($id) {
  37.     try {
  38.         $target_cf = new ColumnFamily(getConn(), $GLOBALS['cf_sessions']);
  39.         $sess_data = $target_cf->get($GLOBALS['site_name'],$columns=array($id));
  40.         return $sess_data[$id];
  41.     } catch (Exception $e) {
  42.         return(false);
  43.     }
  44. }
  45.  
  46. // $session_expiration is in seconds.  if the row isn't touched after the elapsed number of seconds,
  47. // it disappears and invalidates the session.  makes gc($maxlifetime) redundant.
  48. function write($id, $sess_data) {
  49.     try {
  50.         add_record($GLOBALS['cf_sessions'], $GLOBALS['site_name'], array($id => $sess_data), $GLOBALS['session_expiration']);
  51.         return(true);
  52.     } catch (Exception $e) {
  53.         return(false);
  54.     }
  55. }
  56.  
  57. function destroy($id) {
  58.     try {
  59.         $target_cf = new ColumnFamily(getConn(), $GLOBALS['cf_sessions']);
  60.         $target_cf->remove($GLOBALS['site_name'], array($id));
  61.         return(true);
  62.     } catch (Exception $e) {
  63.         return(false);
  64.     }
  65. }
  66.  
  67. function gc($maxlifetime) {
  68.     // handled by col expiry
  69.     return true;
  70. }
  71.  
  72. session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
  73.  
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement