X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FSession.php;h=79a69a96ea3dc11b1f93672890f1687f2e263fa0;hb=b0527801d9c2b84408bbfdf82bbdc5b778f72cfc;hp=6f13c7d2732a1b40e092c0d88b0855664b1d6e95;hpb=5a600a02d134861933ab8d8b49245eb8b77982ec;p=quix0rs-gnu-social.git diff --git a/classes/Session.php b/classes/Session.php index 6f13c7d273..79a69a96ea 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -2,8 +2,8 @@ /** * Table Definition for session * - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2009, Control Yourself, Inc. + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2009, StatusNet, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; @@ -40,6 +40,13 @@ class Session extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + static function logdeb($msg) + { + if (common_config('sessions', 'debug')) { + common_debug("Session: " . $msg); + } + } + static function open($save_path, $session_name) { return true; @@ -52,6 +59,8 @@ class Session extends Memcached_DataObject static function read($id) { + self::logdeb("Fetching session '$id'"); + $session = Session::staticGet('id', $id); if (empty($session)) { @@ -63,6 +72,8 @@ class Session extends Memcached_DataObject static function write($id, $session_data) { + self::logdeb("Writing session '$id'"); + $session = Session::staticGet('id', $id); if (empty($session)) { @@ -74,14 +85,25 @@ class Session extends Memcached_DataObject return $session->insert(); } else { - $session->session_data = $session_data; + if (strcmp($session->session_data, $session_data) == 0) { + self::logdeb("Not writing session '$id'; unchanged"); + return true; + } else { + self::logdeb("Session '$id' data changed; updating"); + + $orig = clone($session); - return $session->update(); + $session->session_data = $session_data; + + return $session->update($orig); + } } } static function destroy($id) { + self::logdeb("Deleting session $id"); + $session = Session::staticGet('id', $id); if (!empty($session)) { @@ -91,19 +113,36 @@ class Session extends Memcached_DataObject static function gc($maxlifetime) { - $epoch = time() - $maxlifetime; + self::logdeb("garbage collection (maxlifetime = $maxlifetime)"); - $qry = 'DELETE FROM session ' . - 'WHERE modified < "'.$epoch.'"'; + $epoch = common_sql_date(time() - $maxlifetime); + + $ids = array(); $session = new Session(); + $session->whereAdd('modified < "'.$epoch.'"'); + $session->selectAdd(); + $session->selectAdd('id'); + + $session->find(); - $session->query($qry); + while ($session->fetch()) { + $ids[] = $session->id; + } + + $session->free(); + + foreach ($ids as $id) { + self::destroy($id); + } } static function setSaveHandler() { - session_set_save_handler('Session::open', 'Session::close', 'Session::read', - 'Session::write', 'Session::destroy', 'Session::gc'); + self::logdeb("setting save handlers"); + $result = session_set_save_handler('Session::open', 'Session::close', 'Session::read', + 'Session::write', 'Session::destroy', 'Session::gc'); + self::logdeb("save handlers result = $result"); + return $result; } }