Source for file Session.php
* Custom Session for work with Memcache
* @use core_view_classes_Memcache_Memcache
die('This file was generated for PHP 5');
* include core_view_classes_Memcache_Memcache
require_once(CFG_BASE_ROOT .
'/core/view/classes/Memcache/Memcache.php');
/* user defined includes */
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FBC-includes begin
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FBC-includes end
/* user defined constants */
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FBC-constants begin
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FBC-constants end
* Custom Session for work with Memcache
* @use core_view_classes_Memcache_Memcache
* The instance of the class Memcache
private static $MC =
null;
* The session expiration time
private static $sessionTime =
1440;
* Unique ID as a prefix for session key
private static $keyPrefix =
'';
* The waiting timeout unlocking session
private static $sleepTime =
100000;
* The session_key_lock expiration time
private static $lockTime =
10;
* The level of compression
private static $gzSize =
300;
* The variable to store the CAS token in
private static $version =
null;
* The session key after prepare
public static $session_key =
'';
* Create a new instance of the class Memcache
* @param string host The hostname of the memcache server
* @param string port The port on which memcache is running
* @param string mPrefix Unique ID as a prefix for memcache key
* @param string sPrefix Unique ID as a prefix for session key
public static function Init($host, $port, $mPrefix, $sPrefix) {
// section -64--88-1--106--4b532b66:12d287c133d:-8000:0000000000001FE8 begin
self::$MC =
new core_view_classes_Memcache_Memcache($host, $port, $mPrefix);
self::$MC->lockTime =
self::$lockTime;
self::$keyPrefix =
$sPrefix;
self::WriteLog(__FUNCTION__
, var_export(array($host, $port, $mPrefix, $sPrefix), true));
// section -64--88-1--106--4b532b66:12d287c133d:-8000:0000000000001FE8 end
* Reads the requested session data
* @param string key Unique session ID
* @param boolean withLock Read session with lock as default value
public static function Read($key, $withLock =
true) {
$returnValue = (string)
'';
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FC0 begin
self::WriteLog(__FUNCTION__
, $key.
', '.
$withLock.
', version - '.
self::$version);
self::$session_key =
self::PrepareKey($key);
while (!self::$MC->Lock(self::$session_key, self::$version)) {
usleep(self::$sleepTime);
$returnValue =
self::$MC->get($key);
if (@$tmp =
gzuncompress($returnValue)) {
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FC0 end
return (string)
$returnValue;
* Writes the provided session data with the requested key
* @param string key Unique session ID
* @param value The value to store
public static function Write($key, $value) {
$returnValue = (bool)
false;
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FC2 begin
self::WriteLog(__FUNCTION__
, $key.
', '.
var_export($value, true).
', version - '.
self::$version);
$session_key =
self::PrepareKey($key);
if (self::$MC->CheckLock($session_key, self::$version)) {
if (mb_strlen($value)>
self::$gzSize) {
$value =
gzcompress($value, 6);
$returnValue =
self::$MC->set($key, $value, self::$sessionTime);
self::$MC->Unlock($session_key);
// section -64--88-1--106--58e7bf35:12d1e1d4191:-8000:0000000000001FC2 end
return (bool)
$returnValue;
* Destroys the requested session
* @param string key Unique session ID
public static function Destroy($key) {
// section -64--88-1--106--44318241:12d1e485c5b:-8000:0000000000001FCC begin
self::WriteLog(__FUNCTION__
, $key.
', '.
$key.
', version - '.
self::$version);
$session_key =
self::PrepareKey($key);
if (self::$MC->CheckLock($session_key, self::$version)) {
$returnValue =
self::$MC->delete($key);
self::$MC->Unlock($session_key);
// section -64--88-1--106--44318241:12d1e485c5b:-8000:0000000000001FCC end
* Make new key for lock session
* @param string key Unique session ID
* @return string Return a new key with prefix
$returnValue = (string)
'';
// section -64--88-1--106--1adfd58c:12d2c271cbb:-8000:000000000000200F begin
$returnValue =
md5(self::$keyPrefix .
$key);
self::WriteLog(__FUNCTION__
, $returnValue);
// section -64--88-1--106--1adfd58c:12d2c271cbb:-8000:000000000000200F end
return (string)
$returnValue;
* Write a text to the log file
* @param string name The function name
* @param string text The string that is to be written
protected static function WriteLog($name, $text =
'') {
// section -64--88-1--106-42af027e:12d32ad9c50:-8000:0000000000002029 begin
// section -64--88-1--106-42af027e:12d32ad9c50:-8000:0000000000002029 end
* Prolong expiration time
* @param int time Prolong time in second
public static function Prolong($time =
10) {
$returnValue = (bool)
false;
// section -64--88-1--106-3b746a61:12de6c64a8f:-8000:00000000000023F6 begin
if (self::$MC->CheckLock(self::$session_key, self::$version)) {
$returnValue =
self::$MC->ProlongLock(self::$session_key, self::$version, $time);
// section -64--88-1--106-3b746a61:12de6c64a8f:-8000:00000000000023F6 end
return (bool)
$returnValue;
* Create a new instance of the class Memcache
private function __construct() {
// section -64--88-1--106--7edefe2a:12de72d82df:-8000:000000000000218E begin
// section -64--88-1--106--7edefe2a:12de72d82df:-8000:000000000000218E end
} /* end of class core_view_classes_Session */
Documentation generated on Thu, 03 Mar 2011 20:14:16 +0300 by phpDocumentor 1.4.3