summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-27 05:48:22 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-27 05:48:22 -0700
commit0ca22cf6e2bd80247520f7c1f83535f8de5fed0a (patch)
tree2a3467c6b7e98dd1c13e2930893a378afb4d007a /classes
parent48d671ac39de0ebfd36858d784d3066ecbb89c10 (diff)
a memcached_dataobject class for saving sessions
Diffstat (limited to 'classes')
-rwxr-xr-xclasses/Session.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/classes/Session.php b/classes/Session.php
index 9b48dabac..6f13c7d27 100755
--- a/classes/Session.php
+++ b/classes/Session.php
@@ -39,4 +39,71 @@ class Session extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ static function open($save_path, $session_name)
+ {
+ return true;
+ }
+
+ static function close()
+ {
+ return true;
+ }
+
+ static function read($id)
+ {
+ $session = Session::staticGet('id', $id);
+
+ if (empty($session)) {
+ return '';
+ } else {
+ return (string)$session->session_data;
+ }
+ }
+
+ static function write($id, $session_data)
+ {
+ $session = Session::staticGet('id', $id);
+
+ if (empty($session)) {
+ $session = new Session();
+
+ $session->id = $id;
+ $session->session_data = $session_data;
+ $session->created = common_sql_now();
+
+ return $session->insert();
+ } else {
+ $session->session_data = $session_data;
+
+ return $session->update();
+ }
+ }
+
+ static function destroy($id)
+ {
+ $session = Session::staticGet('id', $id);
+
+ if (!empty($session)) {
+ return $session->delete();
+ }
+ }
+
+ static function gc($maxlifetime)
+ {
+ $epoch = time() - $maxlifetime;
+
+ $qry = 'DELETE FROM session ' .
+ 'WHERE modified < "'.$epoch.'"';
+
+ $session = new Session();
+
+ $session->query($qry);
+ }
+
+ static function setSaveHandler()
+ {
+ session_set_save_handler('Session::open', 'Session::close', 'Session::read',
+ 'Session::write', 'Session::destroy', 'Session::gc');
+ }
}