-
Notifications
You must be signed in to change notification settings - Fork 0
/
memcached.php
94 lines (80 loc) · 2.14 KB
/
memcached.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @author Aleksandr Matrosov <[email protected]>
*/
$server = '127.0.0.1';
$port = 11211;
set_error_handler(function ($errno, $errstr) {
if ($errno !== 2 && $errno !== 8) {
echo $errstr . '!!!!' . $errno;
}
}, E_WARNING | E_NOTICE);
$m = new Memcached('persistent');
$m->addServer($server, $port);
if (isset($_GET['del'])) {
$m->delete($_GET['del']);
}
if (isset($_GET['flush'])) {
$m->flush();
}
if (isset($_GET['set'])) {
$m->set($_GET['set'], $_GET['value']);
}
$keys = $m->getAllKeys();
$list = [];
foreach ($keys as $eName) {
$content = $m->get($eName);
if ($m->getResultCode() === Memcached::OPT_COMPRESSION) {
$m->delete($eName);
continue;
}
$list[$eName] = [
'key' => $eName,
'value' => unserialize($content) ? unserialize($content) : $content
];
}
restore_error_handler();
ksort($list);
$table = '';
foreach ($list as $i) {
$table .= '<tr><td width="1%"><a href="memcached.php?del=' . $i['key'] . '">X</a></td>' .
'<td>' . $i['key'] . '</td><td>';
if (is_array($i['value'])) {
$table .= '<pre>' . print_r($i['value'], true) . '</pre>';
} else {
$table .= $i['value'];
}
$table .= '</td></tr>';
}
?>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h3>memcached</h3>
<table cellpadding="0" cellspacing="0" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th></th>
<th>key</th>
<th>value</th>
</tr>
</thead>
<tbody>
<?php echo $table ?>
</tbody>
</table>
<div style="text-align: center">
<a href="memcached.php?flush=1">FLUSH</a> <br/>
<br/>
<a href="#" onclick="memcachedSet()">SET</a>
</div>
<script type="text/javascript">
function memcachedSet () {
var key = prompt("Key: ");
var value = prompt("Value: ");
window.location.href = "memcached.php?set=" + key + "&value=" + value;
}
</script>
</body>