Archive: Namaste PHP AMQP framework v1.0 (2017-2020)
952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
This commit is contained in:
207
utilities/deprecated/cashpeak.php.old
Normal file
207
utilities/deprecated/cashpeak.php.old
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* memcache reader utility
|
||||
*
|
||||
* load it - it's self documenting...
|
||||
*
|
||||
* todo: convert to MDB
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* --------
|
||||
* 07-14-17 mks CORE-470: initial coding
|
||||
*
|
||||
*/
|
||||
|
||||
// initialization
|
||||
require_once(dirname(__DIR__) . '/config/bootstrap.inc');
|
||||
|
||||
$sizeA = 0;
|
||||
$sizeB = 0;
|
||||
|
||||
$keyCount = 0;
|
||||
$idHash = null;
|
||||
$errorMsg = null;
|
||||
$hashKey = null;
|
||||
$data = '';
|
||||
$info = null;
|
||||
|
||||
//get current maintenance mode status
|
||||
if (!empty($_REQUEST['maintenanceMessage'])) {
|
||||
gasCache::add('maintenance', gzcompress(json_encode(['maintenanceMessage' => $_REQUEST['maintenanceMessage']])));
|
||||
}
|
||||
|
||||
if ($maintenance = gasCache::get('maintenance')) {
|
||||
if ($maintenance !== 1) {
|
||||
$maintenance = json_decode(gzuncompress($maintenance), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['admin'])) {
|
||||
switch ($_REQUEST['admin']) {
|
||||
case 'getKeys' :
|
||||
$info = gasCache::getAllKeys();
|
||||
$data = '';
|
||||
$foundKeys = array();
|
||||
if (is_array($info)) {
|
||||
sort($info);
|
||||
foreach($info as $row) {
|
||||
if (!in_array($row, $foundKeys)) {
|
||||
$keyCount++;
|
||||
$data .= "<a class='delete' href='?idhash=$row&delete=1'></a>";
|
||||
$data .= "<a class='cachekey' href='?idhash=$row'>$row</a>";
|
||||
$data .= '<br>';
|
||||
$foundKeys[] = $row;
|
||||
}
|
||||
}
|
||||
$data .= '<br><br><br>';
|
||||
$data = 'Key Count: ' . $keyCount . '<br><br>' . $data;
|
||||
}
|
||||
break;
|
||||
case 'getStats' :
|
||||
$data = gasCache::get_stats();
|
||||
break;
|
||||
case 'doFlush' :
|
||||
gasCache::flush_cache();
|
||||
$data = 'Cache has been flushed';
|
||||
break;
|
||||
case 'doDeleteAll':
|
||||
$keys = gasCache::getAllKeys();
|
||||
if (is_array($keys)) {
|
||||
foreach($keys as $key)
|
||||
{
|
||||
if(!gasCache::delete($key))
|
||||
echo "Could not delete one of the keys";
|
||||
}
|
||||
echo "Deleted all keys!";
|
||||
}
|
||||
break;
|
||||
case 'toggleMaintenance':
|
||||
if($maintenance) {
|
||||
gasCache::delete('maintenance');
|
||||
} else {
|
||||
gasCache::add('maintenance', gzcompress(true));
|
||||
}
|
||||
header("Location: ".$_SERVER['SCRIPT_NAME']."?admin=getKeys"); die;
|
||||
break;
|
||||
}
|
||||
} elseif (isset($_REQUEST['idhash'], $_REQUEST['delete'])) {
|
||||
$key = $_REQUEST['idhash'];
|
||||
if(!gasCache::delete($key))
|
||||
$errorMsg[] = 'Could not delete: ' . $key;
|
||||
else {
|
||||
header("Location: ".$_SERVER['SCRIPT_NAME']."?admin=getKeys"); die;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['idhash'])) {
|
||||
$eClass = '';
|
||||
$idHash = htmlspecialchars(trim($_REQUEST['idhash']));
|
||||
$allKeys = empty($info) ? gasCache::getAllKeys() : $info;
|
||||
|
||||
$data = '';
|
||||
$multi = '';
|
||||
$realHash = '';
|
||||
$foundKeys = array();
|
||||
foreach($allKeys as $key) {
|
||||
if (stripos($key, $idHash) !== false and (!in_array($key, $foundKeys))) {
|
||||
$foundKeys[] = $key;
|
||||
$multi .= "<a class='delete' href='?idhash=$key&delete=1'></a>";
|
||||
$multi .= "<a class='cachekey' href='?idhash=$key'>$key</a>";
|
||||
$multi .= '<br>';
|
||||
|
||||
// Side effect is that only the first instance gets saved to $data
|
||||
// but it doesn't matter because if there is more than on e instance
|
||||
// we display all of the instances ($multi) instead of the details
|
||||
if(empty($data)) {
|
||||
$realHash = (strlen($idHash) > 30) ? $key : $idHash; // save the real $idHash of what we might be displaying the details of
|
||||
$data = gasCache::get($realHash);
|
||||
if (is_null($data)) {
|
||||
$data = gasCache::sysGet($realHash);
|
||||
} else {
|
||||
$sizeB = strlen(serialize($data));
|
||||
$data = json_decode(gzuncompress($data), true);
|
||||
$sizeA = strlen(serialize($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(substr_count($multi, '<br>') > 1)
|
||||
$data = $multi;
|
||||
else
|
||||
$idHash = $realHash; // We display the $idHash in the details so display what
|
||||
// the real $idHash is, not what they were looking for
|
||||
|
||||
|
||||
if(empty($data)) {
|
||||
$data = 'key not found in-cache: ' . $idHash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<title>Cash Peak - Better than a ATM!</title>
|
||||
<link rel="stylesheet" href="logger.css" type="text/css">
|
||||
</HEAD>
|
||||
<body>
|
||||
<div class="title">
|
||||
Cash Peak
|
||||
</div>
|
||||
<div class="container">
|
||||
<form method="POST" action="">
|
||||
<fieldset>
|
||||
<legend>Cash Commands</legend>
|
||||
<a href='?admin=getKeys'>Get All Keys</a><br>
|
||||
<a href='?admin=getStats'>Get Cache Stats</a><br>
|
||||
<a href='?admin=doFlush'>Flush Cache</a><br>
|
||||
<a href='?admin=doDeleteAll'>Delete All Keys</a><br>
|
||||
<a href='?admin=toggleMaintenance'>Toggle Maintenance Mode</a> (Status: <?=!empty($maintenance) ? 'ON' : 'OFF'?>)<br/><br/>
|
||||
<textarea rows="3" style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;width: 100%;" name="maintenanceMessage" placeholder="Enter maintenance message here..."><?= !empty($maintenance['maintenanceMessage']) ? $maintenance['maintenanceMessage'] : '' ?></textarea><br/>
|
||||
<br>
|
||||
<input type="submit" value="Set message"/><br/>
|
||||
</fieldset>
|
||||
<br>
|
||||
<label>Find HashToken:</label>
|
||||
<input type="text" name="idhash" size="50%" placeholder=" ...also accepts partial tokens...">
|
||||
<button type="submit">fetch!</button>
|
||||
</form>
|
||||
<div class="rowError">
|
||||
<?php
|
||||
if (is_array($errorMsg)) {
|
||||
foreach($errorMsg as $row) {
|
||||
echo $row . '<br>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="rowData">
|
||||
<?php
|
||||
if (!empty($data)) {
|
||||
if (is_array($data)) {
|
||||
if (!empty($idHash))
|
||||
echo '<div>Hash Key: ' . $realHash . '</div>';
|
||||
if ($sizeA and $sizeB) {
|
||||
echo '<div>Size In-Cache: ' . $sizeB . '</div>';
|
||||
echo '<div>Size In-Memory: ' . $sizeA . '</div>';
|
||||
echo '<div>Compression: ' . sprintf('%2.2f',(($sizeA - $sizeB) / $sizeA) * 100) . '%</div>';
|
||||
}
|
||||
echo "<pre>";
|
||||
var_export($data); // use this one only if you've tweaked your var-dump depth
|
||||
echo "</pre>";
|
||||
} elseif (!empty($realHash)) {
|
||||
echo '<div>Output for: ' . $realHash . COLON;
|
||||
echo $data;
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div
|
||||
</div>
|
||||
</body>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user