forked from amnuts/opcache-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
376 lines (354 loc) · 15.9 KB
/
index.php
File metadata and controls
376 lines (354 loc) · 15.9 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
if (!function_exists('opcache_get_status')) {
die('The Zend OPcache extension does not appear to be installed');
}
$settings = array(
'compress_path_threshold' => 2
);
$validPages = array('overview', 'files', 'reset');
$page = (empty($_GET['page']) || !in_array($_GET['page'], $validPages)
? 'overview'
: strtolower($_GET['page'])
);
if ($page == 'reset') {
opcache_reset();
header('Location: ?page=overview');
}
$opcache_config = opcache_get_configuration();
$opcache_status = opcache_get_status();
if (!empty($opcache_status['scripts'])) {
uasort($opcache_status['scripts'], function($a, $b) {
return $a['hits'] < $b['hits'];
});
}
function memsize($size, $precision = 3, $space = false)
{
$i = 0;
$val = array(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
while (($size / 1024) > 1) {
$size /= 1024;
++$i;
}
return sprintf("%.{$precision}f%s%s",
$size, (($space && $i) ? ' ' : ''), $val[$i]);
}
function rc($at = null)
{
static $i = 0;
if ($at !== null) {
$i = $at;
} else {
echo (++$i % 2 ? 'even' : 'odd');
}
}
$data = array_merge(
$opcache_status['memory_usage'],
$opcache_status['opcache_statistics'],
array(
'total_memory_size' => memsize($opcache_config['directives']['opcache.memory_consumption']),
'used_memory_percentage' => round(100 * (
($opcache_status['memory_usage']['used_memory'] + $opcache_status['memory_usage']['wasted_memory'])
/ $opcache_config['directives']['opcache.memory_consumption'])),
'hit_rate_percentage' => round($opcache_status['opcache_statistics']['opcache_hit_rate']),
'wasted_percentage' => round($opcache_status['memory_usage']['current_wasted_percentage'], 2),
'used_memory_size' => memsize($opcache_status['memory_usage']['used_memory']),
'free_memory_size' => memsize($opcache_status['memory_usage']['free_memory']),
'wasted_memory_size' => memsize($opcache_status['memory_usage']['wasted_memory']),
'files_cached' => number_format($opcache_status['opcache_statistics']['num_cached_scripts']),
'hits_size' => number_format($opcache_status['opcache_statistics']['hits']),
'miss_size' => number_format($opcache_status['opcache_statistics']['misses']),
'blacklist_miss_size' => number_format($opcache_status['opcache_statistics']['blacklist_misses']),
'num_cached_keys_size' => number_format($opcache_status['opcache_statistics']['num_cached_keys']),
'max_cached_keys_size' => number_format($opcache_status['opcache_statistics']['max_cached_keys']),
)
);
$threshold = '';
if ($data['used_memory_percentage'] >= 80) {
$threshold = ' high';
} elseif ($data['used_memory_percentage'] >= 60) {
$threshold = ' mid';
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'
) {
echo json_encode($data);
exit;
}
$host = (function_exists('gethostname')
? gethostname()
: (php_uname('n')
?: (empty($_SERVER['SERVER_NAME'])
? $_SERVER['HOST_NAME']
: $_SERVER['SERVER_NAME']
)
)
);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<style type="text/css">
html{font-family:sans-serif;font-size:100%;line-height:1.2;padding:2em;}
body {font-size:75%;}
.container{overflow:auto;width:100%;position:relative;}
#info{margin-right:290px;}
#counts{position:absolute;top:0;right:0;width:280px;}
#counts div{
padding:1em;
margin-bottom:1em;
border-radius: 5px;
background-image: linear-gradient(bottom, #B7C8CC 21%, #D5DEE0 60%, #E0ECEF 80%);
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.21, #B7C8CC),color-stop(0.6, #D5DEE0),color-stop(0.8, #E0ECEF));
}
#counts p {text-align:center;}
#counts div.values p {text-align:left;}
#counts p span{font-family:'Roboto',sans-serif;}
#counts p span.large{display:block;line-height:90%;font-size:800%;}
table { margin: 0 0 1em 0; border-collapse: collapse; border-color: #fff; width: 100%; }
table caption { text-align: left; font-size: 1.5em; }
table tr { background-color: #99D0DF; border-color: #fff; }
table th { text-align: left; padding: 6px; background-color: #0BA0C8; color: #fff; border-color: #fff; }
table td { padding: 4px 6px; line-height: 1.4em; vertical-align: top; border-color: #fff; }
table tr.odd { background-color: #EFFEFF; }
table tr.even { background-color: #E0ECEF; }
table tr.highlight { background-color: #61C4DF; }
.wsnw { white-space: nowrap; }
.low{color:#000000;}
.mid{color:#550000;}
.high{color:#FF0000;}
span.showmore span.button {
display: inline-block;
margin-right: 5px;
position: relative;
top: -1px;
color: #333333;
background: none repeat scroll 0 0 #DDDDDD;
border-radius: 2px 2px 2px 2px;
font-size: 12px;
font-weight: bold;
height: 12px;
line-height: 6px;
padding: 0 5px;
vertical-align: middle;
cursor: pointer;
}
a.button {
text-decoration: none;
font-size: 110%;
color: #292929;
padding: 10px 26px;
background: -moz-linear-gradient(top, #ffffff 0%, #b4b7b8);
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#b4b7b8));
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
border: 1px solid #a1a1a1;
text-shadow: 0px -1px 0px rgba(000,000,000,0), 0px 1px 0px rgba(255,255,255,0.4);
margin: 0 1em;
white-space: nowrap;
}
span.showmore span.button:hover {
background-color: #CCCCCC;
}
@media screen and (max-width: 700px) {
#info{margin-right:auto;}
#counts{position:relative;display:block;margin-bottom:2em;width:100%;}
}
@media screen and (max-width: 550px) {
a.button{display:block;margin-bottom:2px;}
#frmFilter{width:99% !important;}
}
</style>
<script type="text/javascript">
$(function(){
<?php if ($page == 'overview'): ?>
var realtime = false;
function ping() {
$.ajax({
url: "#",
dataType: "json",
cache: false,
success: function(data){
$('.realtime').each(function(){
$(this).text(data[$(this).attr('data-value')]);
});
}
});
}
$('#toggleRealtime').click(function(){
if (realtime === false) {
realtime = setInterval(function(){ping()}, 5000);
$(this).text('Disable real-time update of stats');
} else {
clearInterval(realtime);
realtime = false;
$(this).text('Enable real-time update of stats');
}
});
<?php endif; ?>
<?php if ($page == 'files'): ?>
$('span.showmore span.button').click(function(){
if ($(this).next().is(":visible")) {
$(this).next().hide();
$(this).css('padding-top', '0').text('…');
} else {
$(this).next().show();
$(this).css('padding-top', '2px').text('«');
}
});
<?php endif; ?>
});
</script>
</head>
<body>
<div style="text-align:center;margin-bottom:2em;">
<p>
<a href="?page=overview" class="button">Overview</a>
<a href="?page=files" class="button">File usage</a>
<a href="?page=reset" class="button" onclick="return confirm('Are you sure you want to reset the cache?');">Reset cache</a>
</p>
</div>
<?php if ($page == 'overview'): ?>
<h2>Overview</h2>
<div class="container">
<div id="counts">
<div>
<p><span class="large <?php echo $threshold; ?>"><span class="realtime" data-value="used_memory_percentage"><?php echo $data['used_memory_percentage']; ?></span>%</span><br/>memory usage</p>
</div>
<div>
<p><span class="large"><span class="realtime" data-value="hit_rate"><?php echo $data['hit_rate_percentage']; ?></span>%</span><br/>hit rate</p>
</div>
<div class="values">
<p><b>total memory:</b> <span data-value="total_memory_size"><?php echo $data['total_memory_size']; ?></span></p>
<p><b>used memory:</b> <span class="realtime" data-value="used_memory_size"><?php echo $data['used_memory_size']; ?></span></p>
<p><b>free memory:</b> <span class="realtime" data-value="free_memory_size"><?php echo $data['free_memory_size']; ?></span></p>
<p><b>wasted memory:</b> <span class="realtime" data-value="wasted_memory_size"><?php echo $data['wasted_memory_size']; ?></span> (<span class="realtime" data-value="wasted_percentage"><?php echo $data['wasted_percentage']; ?></span>%)</p>
<p><b>number of cached files:</b> <span class="realtime" data-value="files_cached"><?php echo $data['files_cached']; ?></span></p>
<p><b>number of hits:</b> <span class="realtime" data-value="hits_size"><?php echo $data['hits_size']; ?></span></p>
<p><b>number of misses:</b> <span class="realtime" data-value="miss_size"><?php echo $data['miss_size']; ?></span></p>
<p><b>blacklist misses:</b> <span class="realtime" data-value="blacklist_miss_size"><?php echo $data['blacklist_miss_size']; ?></span></p>
<p><b>number of cached keys:</b> <span class="realtime" data-value="num_cached_keys_size"><?php echo $data['num_cached_keys_size']; ?></span></p>
<p><b>max cached keys:</b> <span class="realtime" data-value="max_cached_keys_size"><?php echo $data['max_cached_keys_size']; ?></span></p>
</div>
<br />
<p><a href="#" id="toggleRealtime">Enable real-time update of stats</a></p>
</div>
<div id="info">
<table>
<tr><th colspan="2">General info</th></tr>
<tr class="<?php rc(); ?>">
<td>Zend OPcache</td>
<td><?php echo $opcache_config['version']['version']; ?></td>
</tr>
<tr class="<?php rc(); ?>">
<td>PHP</td>
<td><?php echo phpversion(); ?></td>
</tr>
<tr class="<?php rc(); ?>">
<td>Host</td>
<td><?php echo $host; ?></td>
</tr>
<?php if (!empty($_SERVER['SERVER_SOFTWARE'])): ?>
<tr class="<?php rc(); ?>">
<td>Server Software</td>
<td><?php echo $_SERVER['SERVER_SOFTWARE']; ?></td>
</tr>
<?php endif; ?>
<tr class="<?php rc(); ?>">
<td>Start time</td>
<td><?php echo date_format(date_create("@{$data['start_time']}"), 'Y-m-d H:i:s'); ?></td>
</tr>
<tr class="<?php rc(); ?>">
<td>Last reset</td>
<td><?php echo ($data['last_restart_time'] == 0
? '<em>never</em>'
: date_format(date_create("@{$data['last_restart_time']}"), 'Y-m-d H:i:s')); ?></td>
</tr>
</table>
<table>
<tr><th colspan="2">Directives</th></tr>
<?php rc(0); foreach ($opcache_config['directives'] as $d => $v): ?>
<tr class="<?php rc(); ?>">
<td><span title="<?php echo $d; ?>"><?php echo str_replace(array('opcache.', '_'), array('', ' '), $d); ?></span></td>
<td><?php echo (is_bool($v)
? ($v ? '<i>true</i>' : '<i>false</i>')
: $v); ?></td>
</tr>
<?php endforeach; ?>
</table>
<br style="clear:both;" />
</div>
</div>
<?php endif; ?>
<?php if ($page == 'files'): ?>
<h2>File usage</h2>
<p><label>Start typing to filter on script path<br/><input type="text" style="width:40em;" name="filter" id="frmFilter" /><label></p>
<div class="container">
<h3><?php echo $data['files_cached']; ?> file<?php echo ($data['files_cached'] == 1 ? '' : 's'); ?> cached <span id="filterShowing"></span></h3>
<table>
<tr>
<th>Script</th>
<th>Details</th>
</tr>
<?php rc(0); foreach ($opcache_status['scripts'] as $s): ?>
<tr class="<?php rc(); ?>">
<td class="pathname"><?php
$base = basename($s['full_path']);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, dirname($s['full_path'])));
if (!empty($settings['compress_path_threshold'])) {
echo '<span class="showmore"><span class="button">…</span><span class="text" style="display:none;">' . DIRECTORY_SEPARATOR;
echo join(DIRECTORY_SEPARATOR, array_slice($parts, 0, $settings['compress_path_threshold'])) . DIRECTORY_SEPARATOR;
echo '</span>';
echo join(DIRECTORY_SEPARATOR, array_slice($parts, $settings['compress_path_threshold']));
if (count($parts) > $settings['compress_path_threshold']) {
echo DIRECTORY_SEPARATOR;
}
echo "{$base}</span>";
} else {
echo htmlentities($s['full_path'], ENT_COMPAT, 'UTF-8');
}
?>
</td>
<td>
<p>
hits: <?php echo $s['hits']; ?>,
memory: <?php echo memsize($s['memory_consumption']); ?><br />
last used: <?php echo date_format(date_create($s['last_used']), 'Y-m-d H:i:s'); ?>
</p>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<script type="text/javascript">
$(function(){
$('.container table').bind('paint', function(event, params) {
var trs = $('tr:visible', $(this)).not(':first');
trs.removeClass('odd even')
.filter(':odd').addClass('odd')
.end()
.filter(':even').addClass('even');
$('#filterShowing').text(($('#frmFilter').val().length
? trs.length + ' showing due to filter'
: ''
));
});
$('#frmFilter').bind('keyup', function(event){
$('td.pathname').each(function(index){
if (($(this).text().toLowerCase().indexOf($('#frmFilter').val().toLowerCase())) == -1) {
$(this).parent('tr').hide();
} else {
$(this).parent('tr').show();
}
});
$('.container table').trigger('paint');
});
});
</script>
<?php endif; ?>
</body>
</html>