/
Memcache.model.php
executable file
·101 lines (78 loc) · 2.6 KB
/
Memcache.model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* TwistPHP - An open source PHP MVC framework built from the ground up.
* Copyright (C) 2016 Shadow Technologies Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Shadow Technologies Ltd. <contact@shadow-technologies.co.uk>
* @license https://www.gnu.org/licenses/gpl.html GPL License
* @link https://twistphp.com
*/
namespace Twist\Core\Models\Session;
class Memcache{
protected $savePath;
protected $sessionName;
protected $maxLifetime = 0;
public function register(){
//Use files to store the session info
$this->setHandlers();
}
public function __destruct(){
//Save the session upon destruct of the handler
session_write_close();
}
protected function setHandlers(){
session_set_save_handler(
array($this, 'open'),
array($this, 'close'),
array($this, 'read'),
array($this, 'write'),
array($this, 'destroy'),
array($this, 'gc')
);
//the following prevents unexpected effects when using objects as save handlers
register_shutdown_function('session_write_close');
}
public function open($savePath, $sessionName){
$this->savePath = $savePath;
$this->savePath = $sessionName;
$this->maxLifetime = ini_get('session.gc_maxlifetime');
//Nothing to do at this point
return true;
}
public function close(){
//Select OS do not call Garbage Collection, so we will need to do it in close
$this->gc($this->maxLifetime);
return true;
}
public function read($intSessionID){
$mxdOut = null;
$mxdOut = memcached::get(spritnf("sessions/sess_%s",$intSessionID));
return $mxdOut;
}
public function write($intSessionID, $mxdData){
$blOut = false;
$blOut = memcached::set(spritnf("sessions/sess_%s",$intSessionID), $mxdData, $this->maxLifetime);
return $blOut;
}
public function destroy($intSessionID){
memcached::delete(spritnf("sessions/sess_%s",$intSessionID));
return true;
}
public function gc($intMaxLifetime){
//Nothing to do
return true;
}
}