From e2d5e9aa7ca1e59f786a8f7269ea2adf65a49d1b Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Tue, 17 Jan 2012 18:52:40 -0400 Subject: [PATCH] BUG 0000 files and methods for the plugin pmMonitor --- gulliver/system/class.g.php | 67 +++++++++ workflow/engine/classes/class.memcached.php | 152 ++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 workflow/engine/classes/class.memcached.php diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 649122e28..410d1d75a 100755 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -4491,6 +4491,73 @@ function getDirectorySize($path,$maxmtime=0) } return md5($checkSum); } + + /** + * disableEnableINIvariable + disable or enable a variable in ini file, this is useful for editing the env.ini file + automatically get the value, and change to inverse value, I mean from true to false and viceversa + */ + function disableEnableINIvariable( $inifile, $variable ) { + $enabled = 'false'; + if ( file_exists($inifile ) ) { + $fp = fopen( $inifile, 'r' ); + $line = fgets($fp); + $found = false; + $buffer = null; + + while ( !feof($fp) ) { + $config = G::parse_ini_string($line); + if ( isset($config[$variable] )) { + $enabled = $config[$variable]; + $buffer .= sprintf("%s = %d \n", $variable, 1- $enabled ); + $found = true; + } + else { + $buffer .= trim($line) . "\n"; + } + $line = fgets($fp); + } + fclose($fp); + if ( !$found ) $buffer .= sprintf("\n%s = 1 \n", $variable ); + + @file_put_contents( $inifile, $buffer); + } + else { + $contents = file_put_contents($inifile, sprintf("\n%s = 1\n", $variable)); + } + } + + /** + * set a variable in ini file + */ + function setINIvariable( $inifile, $variable, $value ) { + if ( file_exists($inifile ) ) { + $fp = fopen( $inifile, 'r' ); + $line = fgets($fp); + $found = false; + $buffer = null; + + while ( !feof($fp) ) { + $config = G::parse_ini_string($line); + if ( isset($config[$variable] )) { + $enabled = $config[$variable]; + $buffer .= sprintf("%s = %s \n", $variable, $value ); + $found = true; + } + else { + $buffer .= trim($line) . "\n"; + } + $line = fgets($fp); + } + fclose($fp); + if ( !$found ) $buffer .= sprintf("\n%s = $s \n", $variable, $value ); + + file_put_contents( $inifile, $buffer); + } + else { + $contents = file_put_contents($inifile, sprintf("\n%s = $s\n", $variable, $value)); + } + } }; /** diff --git a/workflow/engine/classes/class.memcached.php b/workflow/engine/classes/class.memcached.php new file mode 100644 index 000000000..8a814b7e7 --- /dev/null +++ b/workflow/engine/classes/class.memcached.php @@ -0,0 +1,152 @@ +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + + +/** + * The ProcessMaker memcached class + * @package workflow.engine.ProcessMaker + */ + + 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 $supported = false; + + static private $instance = NULL; + + private function __construct( $workspace ) { + $this->connected = false; + $this->workspace = $workspace; + + if (class_exists('Memcached')) { + $this->mem = new Memcached(); + $this->class = 'Memcached'; + } + 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(); + } + } + + if ( ! MEMCACHED_ENABLED ) { + $this->connected = false; + return false; + } + + } + + /** + * to get singleton instance + * + * @access public + * @return object + */ + function &getSingleton( $workspace ) { + if (self::$instance == NULL) { + self::$instance = new PMmemcached( $workspace ); + } + return self::$instance; + } + + function set($key, $object, $timeout=0) { + if (! $this->connected ) return false; + $this->mem->set( $this->workspace . '_' . $key, $object, false, $timeout) ; + } + + function get($key) { + if (! $this->connected ) return false; + return $this->mem->get( $this->workspace . '_' . $key) ; + } + + function add($key, $value ) { + if (! $this->connected ) return false; + return $this->mem->add( $this->workspace . '_' . $key, $value ) ; + } + + function increment($key, $value ) { + if (! $this->connected ) return false; + return $this->mem->increment( $this->workspace . '_' . $key, $value ) ; + } + + function delete($key) { + if (! $this->connected ) return false; + return $this->mem->delete( $this->workspace . '_' . $key) ; + } + + function flush() { + if (! $this->connected ) return false; + return $this->mem->flush(); + } + + function getStats() { + if (! $this->connected ) return false; + return $status = $this->mem->getStats(); + } + + function printDetails() { + if (! $this->connected ) return false; + $status = $this->mem->getStats(); + echo ""; + 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; + + echo ""; + echo ""; + + $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%)
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"]."
"; + } + + } +