Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
16
 
-
 
17
/**
-
 
18
 * Memcached based session handler.
-
 
19
 *
-
 
20
 * @package    core
-
 
21
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
-
 
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
23
 */
-
 
24
 
16
 
Línea 25... Línea -...
25
namespace core\session;
-
 
26
 
-
 
27
defined('MOODLE_INTERNAL') || die();
17
namespace core\session;
28
 
18
 
29
/**
19
/**
30
 * Memcached based session handler.
20
 * Memcached based session handler.
31
 *
21
 *
Línea 94... Línea 84...
94
        if (!empty($CFG->session_memcached_lock_retry_sleep)) {
84
        if (!empty($CFG->session_memcached_lock_retry_sleep)) {
95
            $this->lockretrysleep = (int)$CFG->session_memcached_lock_retry_sleep;
85
            $this->lockretrysleep = (int)$CFG->session_memcached_lock_retry_sleep;
96
        }
86
        }
97
    }
87
    }
Línea 98... Línea -...
98
 
-
 
99
    /**
88
 
100
     * Start the session.
-
 
101
     * @return bool success
-
 
102
     */
89
    #[\Override]
103
    public function start() {
90
    public function start() {
Línea 104... Línea 91...
104
        ini_set('memcached.sess_locking', $this->requires_write_lock() ? '1' : '0');
91
        ini_set('memcached.sess_locking', $this->requires_write_lock() ? '1' : '0');
105
 
92
 
Línea 130... Línea 117...
130
 
117
 
131
        set_time_limit($default);
118
        set_time_limit($default);
132
        return $result;
119
        return $result;
Línea 133... Línea -...
133
    }
-
 
134
 
120
    }
135
    /**
-
 
136
     * Init session handler.
121
 
137
     */
122
    #[\Override]
138
    public function init() {
123
    public function init() {
139
        if (!extension_loaded('memcached')) {
124
        if (!extension_loaded('memcached')) {
140
            throw new exception('sessionhandlerproblem', 'error', '', null, 'memcached extension is not loaded');
125
            throw new exception('sessionhandlerproblem', 'error', '', null, 'memcached extension is not loaded');
Línea 176... Línea 161...
176
            ini_set('memcached.sess_lock_max_wait', $this->acquiretimeout);
161
            ini_set('memcached.sess_lock_max_wait', $this->acquiretimeout);
177
        }
162
        }
Línea 178... Línea 163...
178
 
163
 
Línea 179... Línea -...
179
    }
-
 
180
 
-
 
181
    /**
-
 
182
     * Check the backend contains data for this session id.
-
 
183
     *
-
 
184
     * Note: this is intended to be called from manager::session_exists() only.
164
    }
185
     *
-
 
186
     * @param string $sid
-
 
187
     * @return bool true if session found.
165
 
188
     */
166
    #[\Override]
189
    public function session_exists($sid) {
167
    public function session_exists($sid) {
190
        if (!$this->servers) {
168
        if (!$this->servers) {
Línea 207... Línea 185...
207
        }
185
        }
Línea 208... Línea 186...
208
 
186
 
209
        return false;
187
        return false;
Línea 210... Línea -...
210
    }
-
 
211
 
-
 
212
    /**
188
    }
213
     * Kill all active sessions, the core sessions table is
-
 
214
     * purged afterwards.
189
 
215
     */
190
    #[\Override]
216
    public function kill_all_sessions() {
191
    public function destroy_all(): bool {
217
        global $DB;
192
        global $DB;
218
        if (!$this->servers) {
193
        if (!$this->servers) {
Línea 219... Línea 194...
219
            return;
194
            return false;
220
        }
195
        }
221
 
196
 
Línea 243... Línea 218...
243
        $rs->close();
218
        $rs->close();
Línea 244... Línea 219...
244
 
219
 
245
        foreach ($memcacheds as $memcached) {
220
        foreach ($memcacheds as $memcached) {
246
            $memcached->quit();
221
            $memcached->quit();
-
 
222
        }
-
 
223
 
247
        }
224
        return parent::destroy_all();
Línea 248... Línea -...
248
    }
-
 
249
 
-
 
250
    /**
225
    }
251
     * Kill one session, the session record is removed afterwards.
-
 
252
     * @param string $sid
226
 
253
     */
227
    #[\Override]
254
    public function kill_session($sid) {
228
    public function destroy(string $id): bool {
255
        if (!$this->servers) {
229
        if (!$this->servers) {
Línea 256... Línea 230...
256
            return;
230
            return false;
257
        }
231
        }
258
 
232
 
Línea 259... Línea 233...
259
        // Go through the list of all servers because
233
        // Go through the list of all servers because
260
        // we do not know where the session handler put the
234
        // we do not know where the session handler put the
261
        // data.
235
        // data.
262
 
236
 
263
        foreach ($this->servers as $server) {
237
        foreach ($this->servers as $server) {
264
            list($host, $port) = $server;
238
            list($host, $port) = $server;
265
            $memcached = new \Memcached();
239
            $memcached = new \Memcached();
-
 
240
            $memcached->addServer($host, $port);
-
 
241
            $memcached->delete($this->prefix . $id);
266
            $memcached->addServer($host, $port);
242
            $memcached->quit();
Línea 267... Línea 243...
267
            $memcached->delete($this->prefix . $sid);
243
        }
268
            $memcached->quit();
244
 
269
        }
245
        return parent::destroy($id);