home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / System / SharedMemory / Memcache.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.8 KB  |  158 lines

  1. <?php
  2. /**
  3. *
  4. * The Memcache driver for SharedMemory
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.0 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category   System
  15. * @package    System_Sharedmemory
  16. * @author     Evgeny Stepanischev <bolk@lixil.ru>
  17. * @copyright  2005 Evgeny Stepanischev
  18. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19. * @version    CVS: $Id:$
  20. * @link       http://pear.php.net/package/System_SharedMemory
  21. */
  22.  
  23. /**
  24. *
  25. * The methods PEAR SharedMemory uses to interact with PHP's Memcached extension
  26. * for interacting with Memcached shared memory
  27. *
  28. * These methods overload the ones declared System_SharedMemory_Common
  29. *
  30. * @category   System
  31. * @package    System_Sharedmemory
  32. * @package    System_Sharedmemory
  33. * @author     Evgeny Stepanischev <bolk@lixil.ru>
  34. * @copyright  2005 Evgeny Stepanischev
  35. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  36. * @version    CVS: $Id:$
  37. * @link       http://pear.php.net/package/System_SharedMemory
  38. */
  39.  
  40.  
  41. require_once 'System/SharedMemory/Common.php';
  42.  
  43. // {{{ class System_SharedMemory_Memache
  44.  
  45. class System_SharedMemory_Memcache extends System_SharedMemory_Common
  46. {
  47.     // {{{ properties
  48.     /**
  49.     * true if plugin was connected to backend
  50.     *
  51.     * @var bool
  52.     *
  53.     * @access private
  54.     */
  55.     var $_connected;
  56.  
  57.     /**
  58.     * Memcache object instance
  59.     *
  60.     * @var object
  61.     *
  62.     * @access private
  63.     */
  64.     var $_mc;
  65.     // }}}
  66.     // {{{ constructor
  67.  
  68.     /**
  69.      * Constructor. Init all variables.
  70.      *
  71.      * @param array $options
  72.      *
  73.      * @access public
  74.      */
  75.     function System_SharedMemory_Memcache($options)
  76.     {
  77.         extract($this->_default($options, array
  78.         (
  79.             'host'  => '127.0.0.1',
  80.             'port'  => 11211,
  81.             'timeout' => false,
  82.             'persistent' => false,
  83.         )));
  84.  
  85.         $func = $persistent ? 'pconnect' : 'connect';
  86.  
  87.         $this->_mc  = &new Memcache;
  88.         $this->_connected = $timeout === false ?
  89.             $this->_mc->$func($host, $port) :
  90.             $this->_mc->$func($host, $port, $timeout);
  91.     }
  92.     // }}}
  93.     // {{{ isConnected()
  94.  
  95.     /**
  96.      * returns true if plugin was 
  97.      * successfully connected to backend
  98.      *
  99.      * @return bool true if connected
  100.      * @access public
  101.      */
  102.     function isConnected()
  103.     {
  104.         return $this->_connected;
  105.     }
  106.     // }}}
  107.     // {{{ get()
  108.  
  109.     /**
  110.      * returns value of variable in shared mem
  111.      *
  112.      * @param string $name name of variable
  113.      *
  114.      * @return mixed value of the variable
  115.      * @access public
  116.      */
  117.     function get($name)
  118.     {
  119.         return $this->_mc->get($name);
  120.     }
  121.     // }}}
  122.     // {{{ set()
  123.  
  124.     /**
  125.      * set value of variable in shared mem
  126.      *
  127.      * @param string $name  name of the variable
  128.      * @param string $value value of the variable
  129.      * @param int $ttl (optional) time to life of the variable
  130.      *
  131.      * @return bool true on success
  132.      * @access public
  133.      */
  134.     function set($name, $value, $ttl = 0)
  135.     {
  136.         return $this->_mc->set($name, $value, 0, $ttl);
  137.     }
  138.     // }}}
  139.     // {{{ rm()
  140.  
  141.     /**
  142.      * remove variable from memory
  143.      *
  144.      * @param string $name  name of the variable
  145.      *
  146.      * @return bool true on success
  147.      * @access public
  148.      */
  149.     function rm($name, $ttl = false)
  150.     {
  151.         return $ttl === false ? 
  152.             $this->_mc->delete($name) :
  153.             $this->_mc->delete($name, $ttl);
  154.     }
  155.     // }}}
  156. }
  157. // }}}
  158. ?>