PageRenderTime 66ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/memcache/source/classes/class_MemcacheManager.php

https://github.com/manifestinteractive/memcachemanager
PHP | 820 lines | 396 code | 63 blank | 361 comment | 116 complexity | 91082d796a57870182a896af09c507d9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?PHP
  2. #################################################################################
  3. ## Developed by Manifest Interactive, LLC ##
  4. ## http://www.manifestinteractive.com ##
  5. ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
  6. ## ##
  7. ## THIS SOFTWARE IS PROVIDED BY MANIFEST INTERACTIVE 'AS IS' AND ANY ##
  8. ## EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ##
  9. ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ##
  10. ## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MANIFEST INTERACTIVE BE ##
  11. ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ##
  12. ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ##
  13. ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ##
  14. ## BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ##
  15. ## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ##
  16. ## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ##
  17. ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ##
  18. ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
  19. ## Author of file: Peter Schmalfeldt ##
  20. #################################################################################
  21. /**
  22. * @category Memcache Manager
  23. * @package MemcacheManager
  24. * @author Peter Schmalfeldt <manifestinteractive@gmail.com>
  25. * @license http://www.apache.org/licenses/LICENSE-2.0
  26. * @link http://code.google.com/p/memcachemanager/
  27. * @link http://groups.google.com/group/memcachemanager
  28. */
  29. /**
  30. * Begin Document
  31. */
  32. class MemcacheManager {
  33. /**
  34. * Main Memcache Object
  35. *
  36. * @var int
  37. * @access private
  38. */
  39. private $mc;
  40. /**
  41. * Encryption Key
  42. *
  43. * @var int
  44. * @access private
  45. */
  46. private $keypass;
  47. /**
  48. * Memcache Servers
  49. *
  50. * @var array
  51. * @access private
  52. */
  53. private $servers;
  54. /**
  55. * Constructor
  56. *
  57. * Create Memcache Manager
  58. * <code>
  59. * <?php
  60. * $mc = new MemcacheManager();
  61. * $mc->addserver('localhost', 11211);
  62. *
  63. * $data = array(
  64. * 'username'=>'memcachelover',
  65. * 'email'=>'me@myemail.com',
  66. * 'displayname'=>'Memcache Lover',
  67. * 'location'=>array(
  68. * 'country'=>'USA',
  69. * 'state'=>'Oregon',
  70. * 'city'=>'Portland'
  71. * )
  72. * );
  73. *
  74. * $mc->add('memcachelover', $data, true, true, true); // adds the key with JSON encoding, encryption and compression
  75. * echo $mc->get('memcachelover', false, false, true); // would echo the uncompressed, but still encrypted key
  76. * echo $mc->get('memcachelover', false, true, true); // would echo the uncompressed, decrypted JSON formatted string
  77. * print_r($mc->get('memcachelover',true, true, true)); // would print the uncompressed, decrypted array
  78. * print_r($mc->statistics()); // this would print the array of usage stats for all servers
  79. * echo $mc->report(); // this would print our custom report
  80. * $mc->flushmc(); // this would fluch all connected servers
  81. * $mc->close(); // this would close all connections
  82. * ?>
  83. * </code>
  84. *
  85. * @access public
  86. */
  87. public function __construct(){
  88. $this->servers = array();
  89. $this->keypass = 'mY*$3Cr3t^p4$sw0Rd'; // change this
  90. if(class_exists('Memcache')) $this->mc = new Memcache;
  91. else trigger_error("PHP Class 'Memcache' does not exist!", E_USER_ERROR);
  92. }
  93. /**
  94. * Callback Handler for failed connection
  95. *
  96. * @param string $host Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  97. * @param int $port Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.
  98. *
  99. * @author Peter Schmalfeldt
  100. * @version 1.0
  101. */
  102. static function _failure($host, $port) {
  103. var_dump(debug_backtrace());
  104. trigger_error("Memcache '$host:$port' Failed", E_USER_ERROR);
  105. }
  106. /**
  107. * Add a memcached server to connection pool
  108. *
  109. * <code>
  110. * <?php
  111. * $mc = new MemcacheManager();
  112. * $mc->addserver('localhost', 11211);
  113. * ?>
  114. * </code>
  115. *
  116. * @param string $host Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  117. * @param int $port Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.
  118. * @access public
  119. */
  120. public function addserver($host, $port){
  121. $this->servers[] = array('host'=>$host, 'port'=>$port);
  122. // add server in offline mode
  123. if(function_exists('memcache_add_server')) $this->mc->addServer($host, $port, false, 1, 1, -1, false);
  124. else trigger_error("PHP Function 'memcache_add_server' does not exist!", E_USER_ERROR);
  125. // place server online with some added parameters to control it
  126. if($this->status($host, $port)==0){
  127. if(function_exists('memcache_set_server_params')) $this->mc->setServerParams($host, $port, 1, 15, true, array(&$this, '_failure'));
  128. else trigger_error("PHP Function 'memcache_set_server_params' does not exist!", E_USER_ERROR);
  129. }
  130. }
  131. /**
  132. * Returns a the servers online/offline status
  133. *
  134. * <code>
  135. * <?php
  136. * $mc = new MemcacheManager();
  137. * $mc->addserver('localhost', 11211);
  138. * if($mc->status()>0) echo 'Connection Established';
  139. * ?>
  140. * </code>
  141. *
  142. * @param string $host Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.
  143. * @param int $port Point to the port where memcached is listening for connections. This parameter is optional and its default value is 11211. Set this parameter to 0 when using UNIX domain sockets.
  144. * @access public
  145. * @return array Returns 0 if server is failed, non-zero otherwise
  146. */
  147. public function status($host, $port){
  148. if(function_exists('memcache_get_server_status')) return $this->mc->getServerStatus($host, $port);
  149. else trigger_error("PHP Function 'memcache_get_server_status' does not exist!", E_USER_ERROR);
  150. }
  151. /**
  152. * Get statistics from all servers in pool
  153. *
  154. * <code>
  155. * <?php
  156. * $mc = new MemcacheManager();
  157. * $mc->addserver('localhost', 11211);
  158. * print_r($mc->statistics());
  159. * ?>
  160. * </code>
  161. *
  162. * @access public
  163. * @return array Returns a two-dimensional associative array of server statistics or FALSE on failure.
  164. */
  165. public function statistics(){
  166. if(function_exists('memcache_get_stats')) return $this->mc->getExtendedStats();
  167. else trigger_error("PHP Function 'memcache_get_stats' does not exist!", E_USER_ERROR);
  168. }
  169. /**
  170. * Immediately invalidates all existing items but doesn't actually free any resources, it only marks all the items as expired, so occupied memory will be overwritten by new items.
  171. * Please note that after flushing, you have to wait about a second to be able to write to Memcached again. If you don't, your data is not saved.
  172. *
  173. * <code>
  174. * <?php
  175. * $mc = new MemcacheManager();
  176. * $mc->addserver('localhost', 11211);
  177. * $mc->flushmc();
  178. * ?>
  179. * </code>
  180. *
  181. * @access public
  182. */
  183. public function flushmc(){
  184. if(function_exists('memcache_flush')) $this->mc->flush();
  185. else trigger_error("PHP Function 'memcache_flush' does not exist!", E_USER_ERROR);
  186. sleep(1); // pause other commands so this has time to finish...
  187. }
  188. /**
  189. * Stores variable $var with $key ONLY if such key doesn't exist at the server yet.
  190. *
  191. * <code>
  192. * <?php
  193. * $mc = new MemcacheManager();
  194. * $mc->addserver('localhost', 11211);
  195. * $mc->add('mykey1', $myarray1, 30, true, true, true);
  196. * $mc->add('mykey2', $myarray2, 30, true, true);
  197. * $mc->add('mykey3', $myarray3, 30, true);
  198. * $mc->add('mykey4', $myarray4, 30);
  199. * $mc->add('mykey5', $myarray5);
  200. * ?>
  201. * </code>
  202. *
  203. * @param string $key The key that will be associated with the item
  204. * @param string $var The variable to store. Strings and integers are stored as is, other types are stored serialized.
  205. * @param int $expire Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  206. * @param bool $json Whether to encode using JSON
  207. * @param bool $encrypt Whether to encrypt string
  208. * @param bool $zlib Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
  209. * @access public
  210. */
  211. public function add($key, $var, $expire=0, $json=false, $encrypt=false, $zlib=false){
  212. if($zlib) $zlib = MEMCACHE_COMPRESSED;
  213. if($json) $var = json_encode($var);
  214. if($encrypt) $var = $this->encrypt($var);
  215. if(function_exists('memcache_add')) $this->mc->add($key, $var, $zlib, $expire);
  216. else trigger_error("PHP Function 'memcache_add' does not exist!", E_USER_ERROR);
  217. }
  218. /**
  219. * Stores an item var with key on the memcached server
  220. *
  221. * <code>
  222. * <?php
  223. * $mc = new MemcacheManager();
  224. * $mc->addserver('localhost', 11211);
  225. * $mc->set('mykey1', $myarray1, 30, true, true, true);
  226. * $mc->set('mykey2', $myarray2, 30, true, true);
  227. * $mc->set('mykey3', $myarray3, 30, true);
  228. * $mc->set('mykey4', $myarray4, 30);
  229. * $mc->set('mykey5', $myarray5);
  230. * ?>
  231. * </code>
  232. *
  233. * @param string $key The key that will be associated with the item
  234. * @param string $var The variable to store. Strings and integers are stored as is, other types are stored serialized.
  235. * @param int $expire Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  236. * @param bool $json Whether to encode using JSON
  237. * @param bool $encrypt Whether to encrypt string
  238. * @param bool $zlib Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
  239. * @access public
  240. */
  241. public function set($key, $var, $expire=0, $json=false, $encrypt=false, $zlib=false){
  242. if($zlib) $zlib = MEMCACHE_COMPRESSED;
  243. if($json) $var = json_encode($var);
  244. if($encrypt) $var = $this->encrypt($var);
  245. if(function_exists('memcache_set')) $this->mc->set($key, $var, $zlib, $expire);
  246. else trigger_error("PHP Function 'memcache_set' does not exist!", E_USER_ERROR);
  247. }
  248. /**
  249. * Should be used to replace value of existing item with key
  250. *
  251. * <code>
  252. * <?php
  253. * $mc = new MemcacheManager();
  254. * $mc->addserver('localhost', 11211);
  255. * $mc->replace('mykey1', $myarray1, 30, true, true, true);
  256. * $mc->replace('mykey2', $myarray2, 30, true, true);
  257. * $mc->replace('mykey3', $myarray3, 30, true);
  258. * $mc->replace('mykey4', $myarray4, 30);
  259. * $mc->replace('mykey5', $myarray5);
  260. * ?>
  261. * </code>
  262. *
  263. * @param string $key The key that will be associated with the item
  264. * @param string $var The variable to store. Strings and integers are stored as is, other types are stored serialized.
  265. * @param int $expire Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
  266. * @param bool $json Whether to encode using JSON
  267. * @param bool $encrypt Whether to encrypt string
  268. * @param bool $zlib Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
  269. * @access public
  270. */
  271. public function replace($key, $var, $expire=0, $json=false, $encrypt=false, $zlib=false){
  272. if($zlib) $zlib = MEMCACHE_COMPRESSED;
  273. if($json) $var = json_encode($var);
  274. if($encrypt) $var = $this->encrypt($var);
  275. if(function_exists('memcache_replace')) $this->mc->replace($key, $var, $zlib, $expire);
  276. else trigger_error("PHP Function 'memcache_replace' does not exist!", E_USER_ERROR);
  277. }
  278. /**
  279. * Retrieve item from the server
  280. *
  281. * <code>
  282. * <?php
  283. * $mc = new MemcacheManager();
  284. * $mc->addserver('localhost', 11211);
  285. * echo $mc->get('mykey1', true, true, true);
  286. * echo $mc->get('mykey2', true, true);
  287. * echo $mc->get('mykey3', true);
  288. * echo $mc->get('mykey4');
  289. * ?>
  290. * </code>
  291. *
  292. * @param string $keys The key or array of keys to fetch
  293. * @param bool $json Whether to decode using JSON
  294. * @param bool $encrypt Whether to decrypt string
  295. * @param bool $zlib Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
  296. * @access public
  297. */
  298. public function get($keys, $json=false, $decrypt=false, $zlib=false){
  299. if($zlib) $zlib = MEMCACHE_COMPRESSED;
  300. if(function_exists('memcache_get')) $var = $this->mc->get($keys, $zlib);
  301. else trigger_error("PHP Function 'memcache_get' does not exist!", E_USER_ERROR);
  302. if($decrypt) $var = $this->decrypt($var);
  303. if($json) $var = json_decode($var, true);
  304. if(function_exists('memcache_get')) return $var;
  305. else trigger_error("PHP Function 'memcache_get' does not exist!", E_USER_ERROR);
  306. }
  307. /**
  308. * Delete item from the server
  309. *
  310. * <code>
  311. * <?php
  312. * $mc = new MemcacheManager();
  313. * $mc->addserver('localhost', 11211);
  314. * $mc->delete('mykey1', 30);
  315. * $mc->delete('mykey2');
  316. * ?>
  317. * </code>
  318. *
  319. * @param string $key The key associated with the item to delete.
  320. * @param int $timeout Execution time of the item. If it's equal to zero, the item will be deleted right away whereas if you set it to 30, the item will be deleted in 30 seconds.
  321. * @access public
  322. */
  323. public function delete($key, $timeout=0){
  324. if(function_exists('memcache_delete')) {
  325. if($this->mc->get($key)) {
  326. $this->mc->delete($key, $timeout);
  327. sleep(1); // pause other commands so this has time to finish...
  328. }
  329. }
  330. else trigger_error("PHP Function 'memcache_delete' does not exist!", E_USER_ERROR);
  331. }
  332. /**
  333. * Increment item's value
  334. *
  335. * <code>
  336. * <?php
  337. * $mc = new MemcacheManager();
  338. * $mc->addserver('localhost', 11211);
  339. * $mc->increment('mykey1', 5);
  340. * $mc->increment('mykey2');
  341. * ?>
  342. * </code>
  343. *
  344. * @param string $key Key of the item to increment
  345. * @param int $value Increment the item by value . Optional and defaults to 1.
  346. * @access public
  347. */
  348. public function increment($key, $value=1){
  349. if(function_exists('memcache_increment')) $this->mc->increment($key, $value);
  350. else trigger_error("PHP Function 'memcache_increment' does not exist!", E_USER_ERROR);
  351. }
  352. /**
  353. * Decrement item's value
  354. *
  355. * <code>
  356. * <?php
  357. * $mc = new MemcacheManager();
  358. * $mc->addserver('localhost', 11211);
  359. * $mc->decrement('mykey1', 5);
  360. * $mc->decrement('mykey2');
  361. * ?>
  362. * </code>
  363. *
  364. * @param string $key Key of the item do decrement.
  365. * @param int $value Decrement the item by value . Optional and defaults to 1.
  366. * @access public
  367. */
  368. public function decrement($key, $value=1){
  369. if(function_exists('memcache_decrement')) $this->mc->decrement($key, $value);
  370. else trigger_error("PHP Function 'memcache_decrement' does not exist!", E_USER_ERROR);
  371. }
  372. /**
  373. * Get statistics from all servers in pool and generate custom report
  374. *
  375. * <code>
  376. * <?php
  377. * $mc = new MemcacheManager();
  378. * $mc->addserver('localhost', 11211);
  379. * echo $mc->report();
  380. * ?>
  381. * </code>
  382. *
  383. * @access public
  384. * @return string HTML Table of statistics.
  385. */
  386. public function report(){
  387. $status = $this->statistics();
  388. // show possible issues ?
  389. $show_issues = true;
  390. $remaining_memory_warn = 1024;
  391. // colors for report
  392. $color_title = '4D89F9';
  393. $color_border = 'E4EDFD';
  394. $color_subtitle = '999';
  395. $color_active = '4D89F9';
  396. $color_inactive = 'C6D9FD';
  397. $color_header = 'C6D9FD';
  398. $color_section = 'E4EDFD';
  399. $color_row1 = 'FFF';
  400. $color_row2 = 'F7F7F7';
  401. $color_text1 = '555';
  402. $color_text2 = '7E94BE';
  403. $color_text_error = '990000';
  404. // table control
  405. $rowheight = 20;
  406. $firstcolwidth = 175;
  407. // add totals for summary
  408. $server_bytes = array();
  409. $server_limit_maxbytes = array();
  410. $total_accepting_conns = 0;
  411. $total_bytes = 0;
  412. $total_bytes_read = 0;
  413. $total_bytes_written = 0;
  414. $total_cas_badval = 0;
  415. $total_cas_hits = 0;
  416. $total_cas_misses = 0;
  417. $total_cmd_flush = 0;
  418. $total_cmd_get = 0;
  419. $total_cmd_set = 0;
  420. $total_conn_yields = 0;
  421. $total_connection_structures = 0;
  422. $total_curr_connections = 0;
  423. $total_curr_items = 0;
  424. $total_decr_hits = 0;
  425. $total_decr_misses = 0;
  426. $total_delete_hits = 0;
  427. $total_delete_misses = 0;
  428. $total_evictions = 0;
  429. $total_get_hits = 0;
  430. $total_get_misses = 0;
  431. $total_incr_hits = 0;
  432. $total_incr_misses = 0;
  433. $total_limit_maxbytes = 0;
  434. $total_listen_disabled_num = 0;
  435. $total_rusage_system = 0;
  436. $total_rusage_user = 0;
  437. $total_servers = 0;
  438. $total_threads = 0;
  439. $total_total_connections = 0;
  440. $total_total_items = 0;
  441. // get totals first for all servers
  442. foreach($status as $host=>$data){
  443. $total_servers += 1;
  444. foreach($data as $key=>$val){
  445. if($key=='accepting_conns') $total_accepting_conns += $val;
  446. if($key=='bytes') {
  447. $total_bytes += $val;
  448. $server_bytes[] = $val;
  449. }
  450. if($key=='bytes_read') $total_bytes_read += $val;
  451. if($key=='bytes_written') $total_bytes_written += $val;
  452. if($key=='cas_badval') $total_cas_badval += $val;
  453. if($key=='cas_hits') $total_cas_hits += $val;
  454. if($key=='cas_misses') $total_cas_misses += $val;
  455. if($key=='cmd_flush') $total_cmd_flush += $val;
  456. if($key=='cmd_get') $total_cmd_get += $val;
  457. if($key=='cmd_set') $total_cmd_set += $val;
  458. if($key=='conn_yields') $total_conn_yields += $val;
  459. if($key=='connection_structures') $total_connection_structures += $val;
  460. if($key=='curr_connections') $total_curr_connections += $val;
  461. if($key=='curr_items') $total_curr_items += $val;
  462. if($key=='decr_hits') $total_decr_hits += $val;
  463. if($key=='decr_misses') $total_decr_misses += $val;
  464. if($key=='delete_hits') $total_delete_hits += $val;
  465. if($key=='delete_misses') $total_delete_misses += $val;
  466. if($key=='evictions') $total_evictions += $val;
  467. if($key=='get_hits') $total_get_hits += $val;
  468. if($key=='get_misses') $total_get_misses += $val;
  469. if($key=='incr_hits') $total_incr_hits += $val;
  470. if($key=='incr_misses') $total_incr_misses += $val;
  471. if($key=='limit_maxbytes') {
  472. $total_limit_maxbytes += $val;
  473. $server_limit_maxbytes[] = $val;
  474. }
  475. if($key=='listen_disabled_num') $total_listen_disabled_num += $val;
  476. if($key=='rusage_system') $total_rusage_system += $val;
  477. if($key=='rusage_user') $total_rusage_user += $val;
  478. if($key=='threads') $total_threads += $val;
  479. if($key=='total_connections') $total_total_connections += $val;
  480. if($key=='total_items') $total_total_items += $val;
  481. }
  482. }
  483. // set image width
  484. $imagewidth = ($total_servers*25);
  485. if($imagewidth < 150 && $total_servers > 1) $imagewidth = 150;
  486. $totalwidth = ($imagewidth+320);
  487. // make text strings and labels ... code only supports up to 26 memcache connections with these labels, if you need more, add labels here (AA, AB ...)
  488. $alpha = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  489. $servers = ($total_servers==1) ? 'Connection':'Connections';
  490. // configure totals for graphs
  491. $imageFreeMemory = round(($total_limit_maxbytes-$total_bytes)/(1024*1024),2);
  492. $imageUsedMemory = round($total_bytes/(1024*1024),2);
  493. $imageUsedPercent = round(($total_bytes/$total_limit_maxbytes)*100,2);
  494. $imageFreePercent = (100-$imageUsedPercent);
  495. $allocatedMemory = $this->bsize($total_limit_maxbytes);
  496. $usedMemory = $this->bsize($total_bytes);
  497. $usedMemoryPercent = round(($total_bytes/$total_limit_maxbytes)*100,2);
  498. $availableMemory = $this->bsize($total_limit_maxbytes-$total_bytes);
  499. $chl = '';
  500. $perc = '';
  501. $totals = '';
  502. for($i=0; $i<$total_servers; $i++){
  503. $totals .= round(($server_bytes[$i]/$server_limit_maxbytes[$i])*100).',';
  504. $chl .= $alpha[$i]."|";
  505. $perc .= '100,';
  506. }
  507. $chl = rtrim($chl,'|');
  508. $perc = rtrim($perc,',');
  509. $totals = rtrim($totals,',');
  510. // start report
  511. $report = "<div id='memcachereport' style='font-family: arial; width: ".($totalwidth+20)."px; margin: 0 auto;'>
  512. <h3 style='font-size: 16px; color: #{$color_title}; white-space: nowrap;'>Memache Report &nbsp;&rsaquo;&nbsp; {$total_servers} Server {$servers}</h3>
  513. <a href='http://www.manifestinteractive.com' style='font-size: 10px; color: #{$color_subtitle}; text-decoration: none;' target='_blank'>Developed by Peter Schmalfeldt of Manifest Interactive, LLC</a>
  514. <table style='font-size: 12px; width: 100%; border: 1px solid #{$color_border}; border-bottom: 0px;' cellpadding='0' cellspacing='0'>";
  515. $report .= "<tr><td align='center' style='padding: 5px;'><img src='http://chart.apis.google.com/chart?cht=p&amp;chd=t:{$imageFreePercent},{$imageUsedPercent}&amp;chs=320x150&amp;chl=Free%20".str_replace(' ', '%20', $availableMemory)."|Used%20".str_replace(' ', '%20', $usedMemory)."&amp;chco={$color_inactive},{$color_active}' style='float: left;' />";
  516. if($total_servers>1) $report .= "<img src='http://chart.apis.google.com/chart?cht=bvs&amp;chs=".($total_servers*25)."x150&amp;chd=t:{$totals}|{$perc}&amp;chco={$color_active},{$color_inactive}&amp;chbh=20&amp;chds=0,100&amp;chl={$chl}&amp;chm=N*f*%,{$color_active},0,-1,9' style='float: right;' />";
  517. $report .= "</td></tr></table>";
  518. // if there is more than one connection, show accumulative summary
  519. if($total_servers>1){
  520. // check for possible issues
  521. $total_evictions_display = ($show_issues && $total_evictions > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_evictions)." !</span>":$total_evictions;
  522. $total_memory_available = ($show_issues && ($total_limit_maxbytes-$total_bytes) < $remaining_memory_warn) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".$this->bsize($total_limit_maxbytes-$total_bytes)." !</span>":$this->bsize($total_limit_maxbytes-$total_bytes);
  523. $total_get_misses_display = ($show_issues && $total_get_misses > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_get_misses)." !</span>":number_format($total_get_misses);
  524. $total_delete_misses_display = ($show_issues && $total_delete_misses > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_delete_misses)." !</span>":number_format($total_delete_misses);
  525. $total_incr_misses_display = ($show_issues && $total_incr_misses > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_incr_misses)." !</span>":number_format($total_incr_misses);
  526. $total_decr_misses_display = ($show_issues && $total_decr_misses > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_decr_misses)." !</span>":number_format($total_decr_misses);
  527. $total_cas_misses_display = ($show_issues && $total_cas_misses > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($total_cas_misses)." !</span>":number_format($total_cas_misses);
  528. // add to report
  529. $report .= "<table style='font-size: 12px; width: 100%; border: 1px solid #{$color_border};' cellpadding='0' cellspacing='0'>
  530. <tr><td colspan='2' style='font-size: 14px; background-color: #{$color_header}; padding: 5px;'><b>Accumulative Memcache Report</b></td></tr>
  531. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Server Statistics</b></td></tr>
  532. <tr style='background-color: #{$color_row1};' title='Total system time for this instance (seconds:microseconds).'><td height='{$rowheight}' align='right' style='color:#{$color_text1}' width='{$firstcolwidth}'>System CPU Usage &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_rusage_system} Seconds</td></tr>
  533. <tr style='background-color: #{$color_row2};' title='Total user time for this instance (seconds:microseconds).'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>User CPU Usage &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_rusage_user} Seconds</td></tr>
  534. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Memory Usage</b></td></tr>
  535. <tr style='background-color: #{$color_row1};' title='Number of bytes this server is allowed to use for storage.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Memory Allocation &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($total_limit_maxbytes)."</td></tr>
  536. <tr style='background-color: #{$color_row2};' title='Current number of bytes used by this server to store items.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Memory In Use &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($total_bytes)."</td></tr>
  537. <tr style='background-color: #{$color_row1};' title='Current number of bytes available to be used by this server to store items.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Memory Available &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_memory_available}</td></tr>
  538. <tr style='background-color: #{$color_row2};' title='Total number of bytes read by this server from network.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Total Read Memory &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($total_bytes_read)."</td></tr>
  539. <tr style='background-color: #{$color_row1};' title='Total number of bytes sent by this server to network.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Total Written Memory &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($total_bytes_written)."</td></tr>
  540. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Connection Information</b></td></tr>
  541. <tr style='background-color: #{$color_row1};' title='Current number of open connections.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Current Connections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($total_curr_connections)."</td></tr>
  542. <tr style='background-color: #{$color_row2};' title='Total number of connections opened since the server started running.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Total Connections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($total_total_connections)."</td></tr>
  543. <tr style='background-color: #{$color_row1};' title='Number of yields for connections.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Connection Yields &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($total_conn_yields)."</td></tr>
  544. <tr style='background-color: #{$color_row2};' title='Number of connection structures allocated by the server.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Connection Structures &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($total_connection_structures)."</td></tr>
  545. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Memcache Statistics</b></td></tr>
  546. <tr style='background-color: #{$color_row1};' title='The number of times socket listeners were disabled due to hitting the connection limit.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Listeners Disabled &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_listen_disabled_num}</td></tr>
  547. <tr style='background-color: #{$color_row2};' title='Number of valid items removed from cache to free memory for new items.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Evections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_evictions_display}</td></tr>
  548. <tr style='background-color: #{$color_row1};' title='Total number of flush requests.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CMD Flush Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cmd_flush}</td></tr>
  549. <tr style='background-color: #{$color_row2};' title='Total number of retrieval requests.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CMD Get Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cmd_get}</td></tr>
  550. <tr style='background-color: #{$color_row1};' title='Total number of storage requests.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CMD Set Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cmd_set}</td></tr>
  551. <tr style='background-color: #{$color_row2};' title='Number of keys that have been compared and swapped, but the comparison (original) value did not match the supplied value.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CAS Bad Value &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cas_badval}</td></tr>
  552. <tr style='background-color: #{$color_row1};' title='Number of keys that have been compared and swapped and found present.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CAS Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cas_hits}</td></tr>
  553. <tr style='background-color: #{$color_row2};' title='Number of items that have been compared and swapped and not found.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>CAS Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_cas_misses_display}</td></tr>
  554. <tr style='background-color: #{$color_row1};' title='Number of keys that have been requested and found present.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Get Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_get_hits}</td></tr>
  555. <tr style='background-color: #{$color_row2};' title='Number of items that have been requested and not found.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Get Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_get_misses_display}</td></tr>
  556. <tr style='background-color: #{$color_row1};' title='Number of keys that have been deleted and found present.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Delete Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_delete_hits}</td></tr>
  557. <tr style='background-color: #{$color_row2};' title='Number of items that have been delete and not found.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Delete Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_delete_misses_display}</td></tr>
  558. <tr style='background-color: #{$color_row1};' title='Number of keys that have been incremented and found present.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Increment Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_incr_hits}</td></tr>
  559. <tr style='background-color: #{$color_row2};' title='Number of items that have been incremented and not found.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Increment Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_incr_misses_display}</td></tr>
  560. <tr style='background-color: #{$color_row1};' title='Number of keys that have been decremented and found present.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Decrement Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_decr_hits}</td></tr>
  561. <tr style='background-color: #{$color_row2};' title='Number of items that have been decremented and not found.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Decrement Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_decr_misses_display}</td></tr>
  562. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Item Information</b></td></tr>
  563. <tr style='background-color: #{$color_row1};' title='Current number of items stored by this instance.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Current Items &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_curr_items}</td></tr>
  564. <tr style='background-color: #{$color_row2};' title='Total number of items stored during the life of this instance.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Total Items &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$total_total_items}</td></tr>
  565. </table>";
  566. }
  567. // show sumamry for each with alpha marker from graph
  568. $i=0;
  569. foreach($status as $host=>$data){
  570. list($host, $port) = split(":", $host, 2);
  571. $letter = ($total_servers>1) ? "[ ".$alpha[$i]." ]&nbsp; ":"";
  572. $currentUsedMemory = $this->bsize($data['bytes']);
  573. $currentAvailableMemory = $this->bsize($data['limit_maxbytes']-$data['bytes']);
  574. $currentUsedPercent = round(($data['bytes']/$data['limit_maxbytes'])*100,2);
  575. $currentFreePercent = (100-$currentUsedPercent);
  576. $accept = ($data['accepting_conns']==1) ? 'Yes':'No';
  577. // check for possible issues
  578. $evictions_display = ($show_issues && $data['evictions'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['evictions'])." !</span>":$data['evictions'];
  579. $memory_available = ($show_issues && ($data['limit_maxbytes']-$data['bytes']) < $remaining_memory_warn) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".$this->bsize($data['limit_maxbytes']-$data['bytes'])." !</span>":$this->bsize($data['limit_maxbytes']-$data['bytes']);
  580. $get_misses_display = ($show_issues && $data['get_misses'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['get_misses'])." !</span>":number_format($data['get_misses']);
  581. $delete_misses_display = ($show_issues && $data['delete_misses'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['delete_misses'])." !</span>":number_format($data['delete_misses']);
  582. $incr_misses_display = ($show_issues && $data['incr_misses'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['incr_misses'])." !</span>":number_format($data['incr_misses']);
  583. $decr_misses_display = ($show_issues && $data['decr_misses'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['decr_misses'])." !</span>":number_format($data['decr_misses']);
  584. $cas_misses_display = ($show_issues && $data['cas_misses'] > 0) ? "<span style='color:#{$color_text_error}; text-decoration:blink;'>".number_format($data['cas_misses'])." !</span>":number_format($data['cas_misses']);
  585. // add to report
  586. $report .= "<table class='memcachereport' style='font-size: 12px; width: 100%; margin-top: 10px; border: 1px solid #{$color_border};' cellpadding='0' cellspacing='0'>";
  587. if($total_servers>1) $report .= "<tr><td colspan='2' style='padding: 5px;' align='center'><img src='http://chart.apis.google.com/chart?cht=p&amp;chd=t:{$currentFreePercent},{$currentUsedPercent}&amp;chs=300x75&amp;chl=Free%20".str_replace(' ', '%20', $currentAvailableMemory)."|Used%20".str_replace(' ', '%20', $currentUsedMemory)."&amp;chco={$color_inactive},{$color_active}' /></td></tr>";
  588. $report .= "<tr><td colspan='2' style='font-size: 14px; background-color: #{$color_header}; padding: 5px;'><b>{$letter}{$host} &nbsp; &nbsp;&rsaquo;&nbsp; {$port}</b></td></tr>
  589. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Server Statistics</b></td></tr>
  590. <tr style='background-color: #{$color_row1};' title='1 or 0 to indicate whether the server is currently accepting connections or not.'><td width='{$firstcolwidth}' align='right' height='{$rowheight}' style='color:#{$color_text1}'>Accepting Connections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$accept."</td></tr>
  591. <tr style='background-color: #{$color_row2};' title='Version string of this instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Memcache Version &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['version']."</td></tr>
  592. <tr style='background-color: #{$color_row1};' title='Process id of the memcached instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Process ID &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['pid']."</td></tr>
  593. <tr style='background-color: #{$color_row2};' title='Size of pointers for this host specified in bits (32 or 64).'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Pointer Size &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['pointer_size']."</td></tr>
  594. <tr style='background-color: #{$color_row1};' title='Number of worker threads requested.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Threads &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['threads']."</td></tr>
  595. <tr style='background-color: #{$color_row1};' title='Total system time for this instance (seconds:microseconds).'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>System CPU Usage &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['rusage_system']."</td></tr>
  596. <tr style='background-color: #{$color_row2};' title='Total user time for this instance (seconds:microseconds).'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>User CPU Usage &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$data['rusage_user']."</td></tr>
  597. <tr style='background-color: #{$color_row1};' title='Start Time for this memcached instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Start Time &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".date('F jS, Y g:i:sA T',$data['time']-$data['uptime'])."</td></tr>
  598. <tr style='background-color: #{$color_row2};' title='Uptime for this memcached instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Uptime &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->duration($data['time']-$data['uptime'])."</td></tr>
  599. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Memory Usage</b></td></tr>
  600. <tr style='background-color: #{$color_row1};' title='Number of bytes this server is allowed to use for storage.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Memory Allocation &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($data['limit_maxbytes'])."</td></tr>
  601. <tr style='background-color: #{$color_row2};' title='Current number of bytes used by this server to store items.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Memory In Use &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($data['bytes'])."</td></tr>
  602. <tr style='background-color: #{$color_row1};' title='Current number of bytes available to be used by this server to store items.'><td height='{$rowheight}' align='right' style='color:#{$color_text1}'>Memory Available &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$memory_available}</td></tr>
  603. <tr style='background-color: #{$color_row2};' title='Total number of bytes read by this server from network.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Total Read Memory &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($data['bytes_read'])."</td></tr>
  604. <tr style='background-color: #{$color_row1};' title='Total number of bytes sent by this server to network.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Total Written Memory &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".$this->bsize($data['bytes_written'])."</td></tr>
  605. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Connection Information</b></td></tr>
  606. <tr style='background-color: #{$color_row1};' title='Current number of open connections.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Current Connections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['curr_connections'])."</td></tr>
  607. <tr style='background-color: #{$color_row2};' title='Total number of connections opened since the server started running. '><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Total Connections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['total_connections'])."</td></tr>
  608. <tr style='background-color: #{$color_row1};' title='Number of yields for connections.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Connection Yields &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['conn_yields'])."</td></tr>
  609. <tr style='background-color: #{$color_row2};' title='Number of connection structures allocated by the server.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Connection Structures &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['connection_structures'])."</td></tr>
  610. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Memcache Statistics</b></td></tr>
  611. <tr style='background-color: #{$color_row1};' title='The number of times socket listeners were disabled due to hitting the connection limit.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Listeners Disabled &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['listen_disabled_num'])."</td></tr>
  612. <tr style='background-color: #{$color_row2};' title='Number of valid items removed from cache to free memory for new items.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Evections &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$evictions_display}</td></tr>
  613. <tr style='background-color: #{$color_row1};' title='Total number of flush requests.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CMD Flush Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['cmd_flush'])."</td></tr>
  614. <tr style='background-color: #{$color_row2};' title='Total number of retrieval requests.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CMD Get Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['cmd_get'])."</td></tr>
  615. <tr style='background-color: #{$color_row1};' title='Total number of storage requests.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CMD Set Used &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['cmd_set'])."</td></tr>
  616. <tr style='background-color: #{$color_row2};' title='Number of keys that have been compared and swapped, but the comparison (original) value did not match the supplied value.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CAS Bad Value &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['cas_badval'])."</td></tr>
  617. <tr style='background-color: #{$color_row1};' title='Number of keys that have been compared and swapped and found present.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CAS Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['cas_hits'])."</td></tr>
  618. <tr style='background-color: #{$color_row2};' title='Number of items that have been compared and swapped and not found.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>CAS Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$cas_misses_display}</td></tr>
  619. <tr style='background-color: #{$color_row1};' title='Number of keys that have been requested and found present.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Get Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['get_hits'])."</td></tr>
  620. <tr style='background-color: #{$color_row2};' title='Number of items that have been requested and not found.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Get Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$get_misses_display}</td></tr>
  621. <tr style='background-color: #{$color_row1};' title='Number of keys that have been deleted and found present.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Delete Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['delete_hits'])."</td></tr>
  622. <tr style='background-color: #{$color_row2};' title='Number of items that have been delete and not found.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Delete Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$delete_misses_display}</td></tr>
  623. <tr style='background-color: #{$color_row1};' title='Number of keys that have been incremented and found present.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Increment Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['incr_hits'])."</td></tr>
  624. <tr style='background-color: #{$color_row2};' title='Number of items that have been incremented and not found.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Increment Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$incr_misses_display}</td></tr>
  625. <tr style='background-color: #{$color_row1};' title='Number of keys that have been decremented and found present.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Decrement Hits &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['decr_hits'])."</td></tr>
  626. <tr style='background-color: #{$color_row2};' title='Number of items that have been decremented and not found.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Decrement Misses &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;{$decr_misses_display}</td></tr>
  627. <tr><td colspan='2' style='font-size: 12px; background-color: #{$color_section}; padding: 5px;'><b>Item Information</b></td></tr>
  628. <tr style='background-color: #{$color_row1};' title='Current number of items stored by this instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Current Items &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['curr_items'])."</td></tr>
  629. <tr style='background-color: #{$color_row2};' title='Total number of items stored during the life of this instance.'><td align='right' height='{$rowheight}' style='color:#{$color_text1}'>Total Items &nbsp;&rsaquo;&nbsp;</td><td style='color:#{$color_text2}'>&nbsp;".number_format($data['total_items'])."</td></tr>
  630. </table><br />";
  631. $i++;
  632. }
  633. $report .= "</div>";
  634. return $report;
  635. }
  636. /**
  637. * Decrypt String with Key
  638. *
  639. * The function decryptString()
  640. *
  641. * @author Peter Schmalfeldt
  642. * @version 1.0
  643. * @param string $string String to Decrypt
  644. * @return string Decrypted String
  645. */
  646. public function decrypt($string){
  647. if(function_exists('mcrypt_module_open')){
  648. $string = base64_decode($string);
  649. if(!$td = mcrypt_module_open('rijndael-256','','ctr','')) return false;
  650. $iv = substr($string,0,32);
  651. $mo = strlen($string)-32;
  652. $em = substr($string,$mo);
  653. $string = substr($string,32,strlen($string)-64);
  654. $mac = $this->pbkdf2($iv.$string,$this->keypass,1000,32);
  655. if($em!==$mac) return false;
  656. if(mcrypt_generic_init($td,$this->keypass,$iv)!==0) return false;
  657. $string = mdecrypt_generic($td,$string);
  658. $string = unserialize($string);
  659. mcrypt_generic_deinit($td);
  660. mcrypt_module_close($td);
  661. return $string;
  662. }
  663. else trigger_error("PHP Function 'mcrypt_module_open' does not exist!", E_USER_ERROR);
  664. }
  665. /**
  666. * Encrypt String with Key
  667. *
  668. * The function encryptString()
  669. *
  670. * @author Peter Schmalfeldt
  671. * @version 1.0
  672. * @param string $string String to Encrypt
  673. * @return string Encoded String
  674. */
  675. public function encrypt($string){
  676. if(function_exists('mcrypt_module_open')){
  677. if(!$td = mcrypt_module_open('rijndael-256','','ctr','')) return false;
  678. $string = serialize($string);
  679. $iv = mcrypt_create_iv(32, MCRYPT_RAND);
  680. if(mcrypt_generic_init($td,$this->keypass,$iv)!==0

Large files files are truncated, but you can click here to view the full file