[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/HTTP_Session/Session/Container/ -> Memcache.php (source)

   1  <?php
   2  
   3  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   4  
   5  /**
   6   * Database container for session data
   7   *
   8   * Memcache database container
   9   *
  10   * PHP version 4
  11   *
  12   * LICENSE: This source file is subject to version 3.0 of the PHP license
  13   * that is available through the world-wide-web at the following URI:
  14   * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  15   * the PHP License and are unable to obtain it through the web, please
  16   * send a note to [email protected] so we can mail you a copy immediately.
  17   *
  18   * @category  HTTP
  19   * @package   HTTP_Session
  20   * @author    Chad Wagner <[email protected]>
  21   * @author    Torsten Roehr <[email protected]>
  22   * @copyright 1997-2007 The PHP Group
  23   * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
  24   * @version   CVS: $Id: Memcache.php,v 1.3 2007/07/14 12:11:55 troehr Exp $
  25   * @link      http://pear.php.net/package/HTTP_Session
  26   * @since     File available since Release 0.5.6
  27   */
  28  
  29  require_once 'HTTP/Session/Container.php';
  30  
  31  /**
  32   * Database container for session data
  33   *
  34   * @category  HTTP
  35   * @package   HTTP_Session
  36   * @author    Chad Wagner <[email protected]>
  37   * @author    Torsten Roehr <[email protected]>
  38   * @copyright 1997-2007 The PHP Group
  39   * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
  40   * @version   Release: @package_version@
  41   * @link      http://pear.php.net/package/HTTP_Session
  42   * @since     Class available since Release 0.5.6
  43   */
  44  class HTTP_Session_Container_Memcache extends HTTP_Session_Container
  45  {
  46      /**
  47       * Memcache connection object
  48       *
  49       * @var     object  Memcache
  50       * @access  private
  51       */
  52      var $mc;
  53  
  54      /**
  55       * Constructor method
  56       *
  57       * $options is an array with the options.<br>
  58       * The options are:
  59       * <ul>
  60       * <li>'memcache' - Memcache object
  61       * <li>'prefix' - Key prefix, default is 'sessiondata:'</li>
  62       * </ul>
  63       *
  64       * @param array $options Options
  65       *
  66       * @access public
  67       * @return object
  68       */
  69      function HTTP_Session_Container_Memcache($options)
  70      {
  71          $this->_setDefaults();
  72  
  73          if (is_array($options)) {
  74              $this->_parseOptions($options);
  75          }
  76      }
  77  
  78      /**
  79       * Connect to database by using the given DSN string
  80       *
  81       * @param string $mc Memcache object
  82       *
  83       * @access private
  84       * @return mixed   Object on error, otherwise bool
  85       */
  86      function _connect($mc)
  87      {
  88          if (is_object($mc) && is_a($mc, 'Memcache')) {
  89              $this->mc = $mc;
  90  
  91          } else {
  92  
  93              return new PEAR_Error('The given memcache object was not valid in file '
  94                                    . __FILE__ . ' at line ' . __LINE__,
  95                                    41,
  96                                    PEAR_ERROR_RETURN,
  97                                    null,
  98                                    null
  99                                   );
 100          }
 101  
 102          return true;
 103      }
 104  
 105      /**
 106       * Set some default options
 107       *
 108       * @access private
 109       * @return void
 110       */
 111      function _setDefaults()
 112      {
 113          $this->options['prefix']   = 'sessiondata:';
 114          $this->options['memcache'] = null;
 115      }
 116  
 117      /**
 118       * Establish connection to a database
 119       *
 120       * @param string $save_path    Save path
 121       * @param string $session_name Session name
 122       *
 123       * @access public
 124       * @return mixed  Object on error, otherwise bool
 125       */
 126      function open($save_path, $session_name)
 127      {
 128          return $this->_connect($this->options['memcache']);
 129      }
 130  
 131      /**
 132       * Free resources
 133       *
 134       * @access public
 135       * @return bool
 136       */
 137      function close()
 138      {
 139          return true;
 140      }
 141  
 142      /**
 143       * Read session data
 144       *
 145       * @param string $id Session id
 146       *
 147       * @access public
 148       * @return mixed
 149       */
 150      function read($id)
 151      {
 152          $result = $this->mc->get($this->options['prefix'] . $id);
 153          return $result;
 154      }
 155  
 156      /**
 157       * Write session data
 158       *
 159       * @param string $id   Session id
 160       * @param mixed  $data Session data
 161       *
 162       * @access public
 163       * @return bool
 164       */
 165      function write($id, $data)
 166      {
 167          $this->mc->set($this->options['prefix'] . $id,
 168                         $data,
 169                         MEMCACHE_COMPRESSED,
 170                         time() + ini_get('session.gc_maxlifetime'));
 171  
 172          return true;
 173      }
 174  
 175      /**
 176       * Destroy session data
 177       *
 178       * @param string $id Session id
 179       *
 180       * @access public
 181       * @return bool
 182       */
 183      function destroy($id)
 184      {
 185          $this->mc->delete($this->options['prefix'] . $id);
 186          return true;
 187      }
 188  
 189      /**
 190       * Garbage collection
 191       *
 192       * @param int $maxlifetime Maximum lifetime
 193       *
 194       * @access public
 195       * @return bool
 196       */
 197      function gc($maxlifetime)
 198      {
 199          return true;
 200      }
 201  }
 202  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1