diff --git a/workflow/engine/classes/class.memcached.php b/workflow/engine/classes/class.memcached.php index 03ee0b605..4cdba77d1 100644 --- a/workflow/engine/classes/class.memcached.php +++ b/workflow/engine/classes/class.memcached.php @@ -1,6 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -30,158 +32,169 @@ * @package workflow.engine.ProcessMaker */ -class PMmemcached { - const ONE_MINUTE = 60; - const ONE_HOUR = 3600; - const TWO_HOURS = 7200; - const EIGHT_HOURS = 28800; +class PMmemcached +{ + const ONE_MINUTE = 60; + const ONE_HOUR = 3600; + const TWO_HOURS = 7200; + const EIGHT_HOURS = 28800; - var $version; - var $mem; - var $connected = false; - var $enabled = false; - var $supported = false; + var $version; + var $mem; + var $connected = false; + var $enabled = false; + var $supported = false; - private static $instance = NULL; + private static $instance = NULL; - public function __construct($workspace) { - $this->enabled = MEMCACHED_ENABLED; - $this->connected = false; - $this->workspace = $workspace; - if (class_exists ( 'Memcached' )) { - $this->mem = new Memcached (); - $this->class = 'Memcached'; - $this->connected = true; - } - else { - if (class_exists ( 'Memcache' )) { - $this->mem = new Memcache (); - $this->class = 'Memcache'; - $this->supported = true; - $this->connected = @$this->mem->connect ( MEMCACHED_SERVER, 11211 ); - if ($this->connected) { - $this->version = $this->mem->getVersion (); + public function __construct ($workspace) + { + $this->enabled = MEMCACHED_ENABLED; + $this->connected = false; + $this->workspace = $workspace; + if (class_exists( 'Memcached' )) { + $this->mem = new Memcached(); + $this->class = 'Memcached'; + $this->connected = true; + } else { + if (class_exists( 'Memcache' )) { + $this->mem = new Memcache(); + $this->class = 'Memcache'; + $this->supported = true; + $this->connected = @$this->mem->connect( MEMCACHED_SERVER, 11211 ); + if ($this->connected) { + $this->version = $this->mem->getVersion(); + } + } else { + G::Loadclass( 'fileCache' ); + // create cache folder + $cacheFolder = PATH_DATA . "sites/" . $workspace . "/cachefiles/"; + if (! file_exists( $cacheFolder )) { + if (! mkdir( $cacheFolder )) { + return false; + } + } + $this->class = 'fileCache'; + $this->connected = true; + $this->mem = new FileCache( $cacheFolder ); + } } - } - else { - G::Loadclass ( 'fileCache' ); - // create cache folder - $cacheFolder = PATH_DATA . "sites/" . $workspace . "/cachefiles/"; - if (! file_exists ( $cacheFolder )) { - if (! mkdir ( $cacheFolder )) { + + if (! MEMCACHED_ENABLED) { + $this->connected = false; return false; - } } - $this->class = 'fileCache'; - $this->connected = true; - $this->mem = new FileCache ( $cacheFolder ); - } + } - if (! MEMCACHED_ENABLED) { - $this->connected = false; - return false; + /** + * to get singleton instance + * + * @access public + * @return object + */ + public static function getSingleton ($workspace) + { + if (! self::$instance instanceof self) { + self::$instance = new PMmemcached( $workspace ); + } + return self::$instance; } - } - - /** - * to get singleton instance - * - * @access public - * @return object - */ - public static function getSingleton($workspace) { - if (! self::$instance instanceof self) { - self::$instance = new PMmemcached ( $workspace ); + public function __clone () + { + throw new Exception( "Clone is not allowed." ); } - return self::$instance; - } - public function __clone() { - throw new Exception ( "Clone is not allowed." ); - } + public function __wakeup () + { + throw new Exception( "Deserializing is not allowed." ); + } - public function __wakeup() { - throw new Exception ( "Deserializing is not allowed." ); - } + function set ($key, $object, $timeout = 0) + { + if (! $this->connected) + return false; + if ($this->class != 'filecache') + $this->mem->set( $this->workspace . '_' . $key, $object, false, $timeout ); + else + $this->mem->set( $this->workspace . '_' . $key, $object ); + } - function set($key, $object, $timeout = 0) { - if (! $this->connected) - return false; - if ($this->class != 'filecache') - $this->mem->set ( $this->workspace . '_' . $key, $object, false, $timeout ); - else - $this->mem->set ( $this->workspace . '_' . $key, $object ); - } + function get ($key) + { + if (! $this->connected) + return false; + return $this->mem->get( $this->workspace . '_' . $key ); + } - function get($key) { - if (! $this->connected) - return false; - return $this->mem->get ( $this->workspace . '_' . $key ); - } + function add ($key, $value) + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + return $this->mem->add( $this->workspace . '_' . $key, $value ); + } - function add($key, $value) { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - return $this->mem->add ( $this->workspace . '_' . $key, $value ); - } + function increment ($key, $value) + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + return $this->mem->increment( $this->workspace . '_' . $key, $value ); + } - function increment($key, $value) { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - return $this->mem->increment ( $this->workspace . '_' . $key, $value ); - } + function delete ($key) + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + return $this->mem->delete( $this->workspace . '_' . $key ); + } - function delete($key) { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - return $this->mem->delete ( $this->workspace . '_' . $key ); - } + function flush () + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + return $this->mem->flush(); + } - function flush() { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - return $this->mem->flush (); - } + function getStats () + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + return $status = $this->mem->getStats(); + } - function getStats() { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - return $status = $this->mem->getStats (); - } + function printDetails () + { + if ((! $this->connected) || ($this->class == 'filecache')) + return false; + $status = $this->mem->getStats(); + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; - function printDetails() { - if ((! $this->connected) || ($this->class == 'filecache')) - return false; - $status = $this->mem->getStats (); - echo "
Memcache Server version: " . $status["version"] . "
Number of hours this server has been running " . ($status["uptime"] / 3660) . "
Total number of items stored by this server ever since it started " . $status["total_items"] . "
Number of open connections " . $status["curr_connections"] . "
Total number of connections opened since the server started running " . $status["total_connections"] . "
Number of connection structures allocated by the server " . $status["connection_structures"] . "
Cumulative number of retrieval requests " . $status["cmd_get"] . "
Cumulative number of storage requests " . $status["cmd_set"] . "
"; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + $percCacheHit = ((real) $status["get_hits"] / (real) $status["cmd_get"] * 100); + $percCacheHit = round( $percCacheHit, 3 ); + $percCacheMiss = 100 - $percCacheHit; - $percCacheHit = (( real ) $status ["get_hits"] / ( real ) $status ["cmd_get"] * 100); - $percCacheHit = round ( $percCacheHit, 3 ); - $percCacheMiss = 100 - $percCacheHit; + echo ""; + echo ""; - echo ""; - echo ""; + $MBRead = (real) $status["bytes_read"] / (1024 * 1024); - $MBRead = ( real ) $status ["bytes_read"] / (1024 * 1024); - - echo ""; - $MBWrite = ( real ) $status ["bytes_written"] / (1024 * 1024); - echo ""; - $MBSize = ( real ) $status ["limit_maxbytes"] / (1024 * 1024); - echo ""; - echo ""; - echo "
Memcache Server version: " . $status ["version"] . "
Number of hours this server has been running " . ($status ["uptime"] / 3660) . "
Total number of items stored by this server ever since it started " . $status ["total_items"] . "
Number of open connections " . $status ["curr_connections"] . "
Total number of connections opened since the server started running " . $status ["total_connections"] . "
Number of connection structures allocated by the server " . $status ["connection_structures"] . "
Cumulative number of retrieval requests " . $status ["cmd_get"] . "
Cumulative number of storage requests " . $status ["cmd_set"] . "
Number of keys that have been requested and found present " . $status["get_hits"] . " ($percCacheHit%)
Number of items that have been requested and not found " . $status["get_misses"] . "($percCacheMiss%)
Number of keys that have been requested and found present " . $status ["get_hits"] . " ($percCacheHit%)
Number of items that have been requested and not found " . $status ["get_misses"] . "($percCacheMiss%)
Total number of bytes read by this server from network " . $MBRead . " Mega Bytes
Total number of bytes sent by this server to network " . $MBWrite . " Mega Bytes
Number of bytes this server is allowed to use for storage." . $MBSize . " Mega Bytes
Number of valid items removed from cache to free memory for new items." . $status ["evictions"] . "
"; - } + echo "Total number of bytes read by this server from network " . $MBRead . " Mega Bytes"; + $MBWrite = (real) $status["bytes_written"] / (1024 * 1024); + echo "Total number of bytes sent by this server to network " . $MBWrite . " Mega Bytes"; + $MBSize = (real) $status["limit_maxbytes"] / (1024 * 1024); + echo "Number of bytes this server is allowed to use for storage." . $MBSize . " Mega Bytes"; + echo "Number of valid items removed from cache to free memory for new items." . $status["evictions"] . ""; + echo ""; + } }