]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Session/MemcacheSessionHandler.php
Line endings are converted to unix style
[friendica.git] / src / Core / Session / MemcacheSessionHandler.php
index dce206e64cbaa5efb00ddb2641a9b67935b46093..0bc5e8bfe924ea8d95bd7fb2252924734986b5db 100644 (file)
-<?php\r
-\r
-namespace Friendica\Core\Session;\r
-\r
-use Friendica\BaseObject;\r
-use Friendica\Core\Session;\r
-use SessionHandlerInterface;\r
-use Memcache;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * SessionHandler using Memcache\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface\r
-{\r
-       /**\r
-        * @var Memcache\r
-        */\r
-       private $memcache = null;\r
-\r
-       /**\r
-        *\r
-        * @param Memcache $memcache\r
-        */\r
-       public function __construct(Memcache $memcache)\r
-       {\r
-               $this->memcache = $memcache;\r
-       }\r
-\r
-       public function open($save_path, $session_name)\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function read($session_id)\r
-       {\r
-               if (!x($session_id)) {\r
-                       return '';\r
-               }\r
-\r
-               $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);\r
-               if (!is_bool($data)) {\r
-                       Session::$exists = true;\r
-                       return $data;\r
-               }\r
-               logger("no data for session $session_id", LOGGER_TRACE);\r
-               return '';\r
-       }\r
-\r
-       /**\r
-        * @brief Standard PHP session write callback\r
-        *\r
-        * This callback updates the stored session data and/or the expiration depending\r
-        * on the case. Uses the Session::expire for existing session, 5 minutes\r
-        * for newly created session.\r
-        *\r
-        * @param  string $session_id   Session ID with format: [a-z0-9]{26}\r
-        * @param  string $session_data Serialized session data\r
-        * @return boolean Returns false if parameters are missing, true otherwise\r
-        */\r
-       public function write($session_id, $session_data)\r
-       {\r
-               if (!$session_id) {\r
-                       return false;\r
-               }\r
-\r
-               if (!$session_data) {\r
-                       return true;\r
-               }\r
-\r
-               $expire = time() + Session::$expire;\r
-\r
-               $this->memcache->set(\r
-                       self::getApp()->get_hostname() . ":session:" . $session_id,\r
-                       $session_data,\r
-                       MEMCACHE_COMPRESSED,\r
-                       $expire\r
-               );\r
-\r
-               return true;\r
-       }\r
-\r
-       public function close()\r
-       {\r
-               return true;\r
-       }\r
-\r
-       public function destroy($id)\r
-       {\r
-               $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);\r
-               return true;\r
-       }\r
-\r
-       public function gc($maxlifetime)\r
-       {\r
-               return true;\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Core\Session;
+
+use Friendica\BaseObject;
+use Friendica\Core\Session;
+use SessionHandlerInterface;
+use Memcache;
+
+require_once 'boot.php';
+require_once 'include/text.php';
+
+/**
+ * SessionHandler using Memcache
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface
+{
+       /**
+        * @var Memcache
+        */
+       private $memcache = null;
+
+       /**
+        *
+        * @param Memcache $memcache
+        */
+       public function __construct(Memcache $memcache)
+       {
+               $this->memcache = $memcache;
+       }
+
+       public function open($save_path, $session_name)
+       {
+               return true;
+       }
+
+       public function read($session_id)
+       {
+               if (!x($session_id)) {
+                       return '';
+               }
+
+               $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);
+               if (!is_bool($data)) {
+                       Session::$exists = true;
+                       return $data;
+               }
+               logger("no data for session $session_id", LOGGER_TRACE);
+               return '';
+       }
+
+       /**
+        * @brief Standard PHP session write callback
+        *
+        * This callback updates the stored session data and/or the expiration depending
+        * on the case. Uses the Session::expire for existing session, 5 minutes
+        * for newly created session.
+        *
+        * @param  string $session_id   Session ID with format: [a-z0-9]{26}
+        * @param  string $session_data Serialized session data
+        * @return boolean Returns false if parameters are missing, true otherwise
+        */
+       public function write($session_id, $session_data)
+       {
+               if (!$session_id) {
+                       return false;
+               }
+
+               if (!$session_data) {
+                       return true;
+               }
+
+               $expire = time() + Session::$expire;
+
+               $this->memcache->set(
+                       self::getApp()->get_hostname() . ":session:" . $session_id,
+                       $session_data,
+                       MEMCACHE_COMPRESSED,
+                       $expire
+               );
+
+               return true;
+       }
+
+       public function close()
+       {
+               return true;
+       }
+
+       public function destroy($id)
+       {
+               $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);
+               return true;
+       }
+
+       public function gc($maxlifetime)
+       {
+               return true;
+       }
+}