3 namespace Friendica\Core\Session;
5 use Friendica\BaseObject;
6 use Friendica\Core\Session;
7 use SessionHandlerInterface;
10 require_once 'boot.php';
11 require_once 'include/text.php';
14 * SessionHandler using Memcache
16 * @author Hypolite Petovan <mrpetovan@gmail.com>
18 class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface
23 private $memcache = null;
27 * @param Memcache $memcache
29 public function __construct(Memcache $memcache)
31 $this->memcache = $memcache;
34 public function open($save_path, $session_name)
39 public function read($session_id)
41 if (!x($session_id)) {
45 $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);
46 if (!is_bool($data)) {
47 Session::$exists = true;
50 logger("no data for session $session_id", LOGGER_TRACE);
55 * @brief Standard PHP session write callback
57 * This callback updates the stored session data and/or the expiration depending
58 * on the case. Uses the Session::expire for existing session, 5 minutes
59 * for newly created session.
61 * @param string $session_id Session ID with format: [a-z0-9]{26}
62 * @param string $session_data Serialized session data
63 * @return boolean Returns false if parameters are missing, true otherwise
65 public function write($session_id, $session_data)
75 $expire = time() + Session::$expire;
78 self::getApp()->get_hostname() . ":session:" . $session_id,
87 public function close()
92 public function destroy($id)
94 $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);
98 public function gc($maxlifetime)