AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alo
    • Cache
    • Controller
    • Db
    • Exception
    • Session
    • Statics
    • Test
    • Validators
  • Controller
  • None
  • PHP

Classes

  • AbstractSession
  • MemcachedSession
  • SQLSession
 1 <?php
 2 
 3    namespace Alo\Session;
 4 
 5    use Alo;
 6    use Alo\Cache\AbstractCache;
 7    use Alo\Cache\MemcachedWrapper;
 8    use Alo\Exception\ExtensionException as EE;
 9 
10    if (!defined('GEN_START')) {
11       http_response_code(404);
12       die();
13    }
14 
15    /**
16     * The Memcached-based session handler. ALO_SESSION_CLEANUP is not used here as
17     * cleanup is handled by the MySQL event handler
18     *
19     * @author  Art <a.molcanovas@gmail.com>
20     * @package Session
21     */
22    class MemcachedSession extends AbstractSession {
23 
24       /**
25        * Reference to database instance
26        *
27        * @var AbstractCache
28        */
29       protected $mc;
30 
31       /**
32        * Instantiates the class
33        *
34        * @author Art <a.molcanovas@gmail.com>
35        * @throws EE When a caching class is not available
36        */
37       function __construct() {
38          if (!Alo::$cache) {
39             Alo::$cache = new MemcachedWrapper(true);
40          }
41 
42          if (!AbstractCache::is_available()) {
43             throw new EE('No caching PHP extension is loaded', EE::E_EXT_NOT_LOADED);
44          } else {
45             $this->mc = &Alo::$cache;
46             parent::__construct();
47             \Log::debug('Initialised Memcached session');
48          }
49       }
50 
51       protected function write() {
52          $this->mc->set(ALO_SESSION_MC_PREFIX . $this->id, $this->data, ALO_SESSION_TIMEOUT);
53          \Log::debug('Saved session data');
54 
55          return $this;
56       }
57 
58       protected function fetch() {
59          $data = $this->mc->get(ALO_SESSION_MC_PREFIX . $this->id);
60 
61          if ($data) {
62             $this->data = $data;
63          }
64 
65          \Log::debug('Fetched session data');
66 
67          return $this;
68       }
69 
70       function terminate() {
71          $this->mc->delete(ALO_SESSION_MC_PREFIX . $this->id);
72 
73          return parent::terminate();
74       }
75 
76    }
AloFramework documentation API documentation generated by ApiGen 2.8.0