PluginProbe
Docket Cache – Object Cache Accelerator / 24.07.03
Docket Cache – Object Cache Accelerator v24.07.03
26.04.05 trunk 22.07.01 22.07.02 22.07.03 22.07.04 22.07.05 23.08.01 23.08.02 24.07.01 24.07.02 24.07.03 24.07.04 24.07.05 24.07.06 24.07.07 26.04.03 26.04.04
docket-cache / includes / admin / opcviewer.php

opcviewer.php in Docket Cache – Object Cache Accelerator 24.07.03, at includes/admin/opcviewer.php

283 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Docket Cache.
4 *
5 * @author Nawawi Jamili
6 * @license MIT
7 *
8 * @see https://github.com/nawawi/docket-cache
9 */
10
11 namespace Nawawi\DocketCache;
12
13 \defined('ABSPATH') || exit;
14 $opcache_view = $this->opcache_view();
15 $is_config = !empty($_GET['adx']) && 'cnf' === sanitize_text_field($_GET['adx']);
16 ?>
17 <div class="section cronbot opcache">
18 <div class="flex-container">
19 <div class="row">
20 <?php
21 if ($is_config && $this->pt->is_opcache_enable()) :
22 $this->tab_title(esc_html__('OPcache Config', 'docket-cache'));
23 $config = $opcache_view->get_config();
24 if (empty($config)) :
25 echo Resc::boxmsg(__('No data is available. The opcache_get_configuration function disabled in PHP configuration.', 'docket-cache'), 'warning', false, true, false);
26 else :
27 ?>
28 <table class="form-table opcconfig">
29 <tr>
30 <td colspan="2" class="stitle">
31 <?php esc_html_e('Version', 'docket-cache'); ?>
32 </td>
33 </tr>
34 <?php
35 $last = \count($config['version']);
36 $lcnt = 1;
37 foreach ($config['version'] as $k => $v) :
38 ?>
39 <tr>
40 <th<?php echo $lcnt >= $last ? ' class="border-b"' : ''; ?>><?php echo $k; ?><span class="rsep">:</span></th>
41 <td><?php echo $v; ?></td>
42 </tr>
43 <?php
44 ++$lcnt;
45 endforeach;
46 ?>
47
48 <tr>
49 <td colspan="2" class="stitle">
50 <?php esc_html_e('Directives', 'docket-cache'); ?>
51 </td>
52 </tr>
53 <?php
54 foreach ($config['directives'] as $k => $v) :
55 $type = \gettype($v);
56 switch ($type) {
57 case 'boolean':
58 $v = $v ? 'true' : 'false';
59 break;
60 case 'string':
61 $v = '' === $v ? esc_html__('Not set', 'docket-cache') : $v;
62 break;
63 case 'integer':
64 switch ($k) {
65 case 'opcache.memory_consumption':
66 $v = $this->pt->normalize_size($v);
67 break;
68 }
69 break;
70 }
71 $blacklist = [];
72 if ('opcache.blacklist_filename' === $k) {
73 $files = glob($v);
74 if (!empty($files) && \is_array($files)) {
75 $blacklist = $files;
76 }
77 unset($files);
78 }
79 ?>
80 <tr>
81 <th><a href="<?php echo $opcache_view->get_doc($k); ?>" rel="noopener" target="new"><?php echo $k; ?></a><span class="rsep">:</span></th>
82 <td><?php echo $v; ?></td>
83 </tr>
84 <?php if (!empty($blacklist)) : ?>
85 <tr>
86 <th></th>
87 <td><small><?php echo implode('<br>', $blacklist); ?></small></td>
88 </tr>
89 <?php endif; ?>
90
91 <?php endforeach; ?>
92 </table>
93 <p class="submit">
94 <a href="<?php echo $this->pt->get_page(['idx' => 'opcviewer']); ?>" class="button button-primary"><?php esc_html_e('Dismiss', 'docket-cache'); ?></a>
95 </p>
96 <?php
97 endif; // empty config
98 else :
99 ?>
100
101 <?php $this->tab_title(esc_html__('OPcache Usage', 'docket-cache')); ?>
102 <?php
103 if (!$this->pt->is_opcache_enable()) :
104 echo Resc::boxmsg(__('OPcache not available.', 'docket-cache'), 'warning', false, true, false);
105 elseif (!\is_object($opcache_view)) :
106 echo Resc::boxmsg(__('Failed to load OPcacheList()', 'docket-cache'), 'error', false, true, false);
107 else :
108
109 if (!$this->pt->opcache_function_exists('opcache_get_status')) {
110 echo Resc::boxmsg(__('No data is available. The opcache_get_status function disabled in PHP configuration.', 'docket-cache'), 'warning', false, true, false);
111 } elseif ($this->pt->is_opcache_blacklisted()) {
112 echo Resc::boxmsg(__("This site's local path has been blacklisted by OPcache configuration, which prevents it from caching.", 'docket-cache'), 'warning', false, true, false);
113 }
114
115 $stats = $opcache_view->get_usage();
116
117 if (empty($stats->file_cache_only)) :
118 ?>
119 <table class="form-table">
120 <tr>
121 <td colspan="4" class="stitle">
122 <?php esc_html_e('Statistics', 'docket-cache'); ?>
123 </td>
124 </tr>
125 <tr>
126 <th><?php esc_html_e('Cache Hits', 'docket-cache'); ?></th>
127 <td class="td-second"><?php echo $stats->hits; ?></td>
128 <th class="th-third"><?php esc_html_e('Cache Misses', 'docket-cache'); ?></th>
129 <td><?php echo $stats->misses; ?></td>
130 </tr>
131 <tr>
132 <th><?php esc_html_e('Cached Files', 'docket-cache'); ?></th>
133 <td class="td-second"><?php echo $stats->num_cached_scripts; ?></td>
134 <th class="th-third"><?php esc_html_e('Cached Keys', 'docket-cache'); ?></th>
135 <td><?php echo $stats->num_cached_keys; ?></td>
136 </tr>
137 <?php if (0 !== (int) $stats->blacklist_misses) : ?>
138 <tr>
139 <th class="border-b"><?php esc_html_e('Max Cached Keys', 'docket-cache'); ?></th>
140 <td class="td-second"><?php echo $stats->max_cached_keys; ?></td>
141 <th class="border-b th-third"><?php esc_html_e('Hit Rate', 'docket-cache'); ?></th>
142 <td><?php echo round($stats->opcache_hit_rate, 0); ?>%</td>
143 </tr>
144 <tr>
145 <th class="border-b"><?php esc_html_e('Blacklist Misses', 'docket-cache'); ?></th>
146 <td class="td-second"><?php echo $stats->blacklist_misses; ?></td>
147 <th class="border-b th-third"><?php esc_html_e('Blacklist Miss Ratio', 'docket-cache'); ?></th>
148 <td><?php echo round($stats->blacklist_miss_ratio, 0); ?>%</td>
149 </tr>
150 <?php else : ?>
151 <tr>
152 <th class="border-b"><?php esc_html_e('Max Cached Keys', 'docket-cache'); ?></th>
153 <td class="td-second"><?php echo $stats->max_cached_keys; ?></td>
154 <th class="border-b th-third"><?php esc_html_e('Hit Rate', 'docket-cache'); ?></th>
155 <td><?php echo round($stats->opcache_hit_rate, 0); ?>%</td>
156 </tr>
157 <?php endif; ?>
158 <tr>
159 <td colspan="4" class="stitle">
160 <?php esc_html_e('Memory Usage', 'docket-cache'); ?>
161 </td>
162 </tr>
163 <tr>
164 <th><?php esc_html_e('Used Memory', 'docket-cache'); ?></th>
165 <td class="td-second"><?php echo $this->pt->normalize_size($stats->used_memory); ?></td>
166 <th class="th-third"><?php esc_html_e('Free Memory', 'docket-cache'); ?></th>
167 <td><?php echo $this->pt->normalize_size($stats->free_memory); ?></td>
168 </tr>
169 <tr>
170 <th><?php esc_html_e('Wasted Memory', 'docket-cache'); ?></th>
171 <td class="td-second"><?php echo $this->pt->normalize_size($stats->wasted_memory); ?></td>
172 <th class="th-third"><?php esc_html_e('Current Wasted', 'docket-cache'); ?></th>
173 <td><?php echo round($stats->current_wasted_percentage, 0); ?>%</td>
174 </tr>
175 </table>
176 <?php else : ?>
177
178 <table class="form-table">
179 <tr>
180 <th><?php esc_html_e('Status', 'docket-cache'); ?></th>
181 <td><a href="https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.file-cache-only" rel="noopener" target="new"><?php esc_html_e('File Cache Only', 'docket-cache'); ?></a></td>
182 </tr>
183 <tr>
184 <th><?php esc_html_e('File Cache Path', 'docket-cache'); ?></th>
185 <td><?php echo $stats->file_cache; ?></td>
186 </tr>
187 <tr>
188 <th><?php esc_html_e('Stats', 'docket-cache'); ?></th>
189 <td><?php echo $stats->statsfile; ?></td>
190 </tr>
191 </table>
192
193 <?php endif; ?>
194
195 <p id="scrollmark" class="submit">
196 <a href="<?php echo $this->pt->action_query('flush-opcache', ['idx' => 'opcviewer']); ?>" class="button button-primary button-large btx-spinner"><?php esc_html_e('Flush OPcache', 'docket-cache'); ?></a>
197 <a href="
198 <?php
199 echo $this->pt->get_page(
200 [
201 'idx' => 'opcviewer',
202 'adx' => 'cnf',
203 ]
204 );
205 ?>
206 " class="button button-secondary button-large btx-spinner"><?php esc_html_e('Display Config', 'docket-cache'); ?></a>
207 </p>
208
209 <?php $this->tab_title(esc_html__('OPcache Files', 'docket-cache'), 'title-below'); ?>
210 <div class="gridlist grid-opclist border-t">
211 <div class="box-left">
212 <form id="config-filter" method="get" action="<?php echo esc_url($this->pt->get_page()); ?>">
213 <input type="hidden" name="page" value="docket-cache-opcviewer">
214 <input type="hidden" name="idx" value="opcviewer">
215 <select id="statsop" name="sf" class="config-filter">
216 <?php
217 $sort_sf = !empty($_GET['sf']) ? sanitize_text_field($_GET['sf']) : 'obc';
218 $opts = [
219 'obc' => __('Object Cache Files', 'docket-cache'),
220 'wpc' => __('Other Files', 'docket-cache'),
221 'dfc' => __('Stale Files', 'docket-cache'),
222 'all' => __('All', 'docket-cache'),
223 ];
224
225 if (!empty($stats->file_cache_only)) {
226 unset($opts['dfc']);
227 }
228
229 foreach ($opts as $k => $n) {
230 echo '<option value="'.$k.'"'.($sort_sf === $k ? ' selected' : '').'>'.$n.'</option>';
231 }
232 ?>
233 </select>
234
235 <select id="statslm" name="sm" class="config-filter">
236 <?php
237 $sort_sm = !empty($_GET['sm']) ? sanitize_text_field($_GET['sm']) : '1k';
238 foreach ([
239 '1k' => __('< 1000 Items', 'docket-cache'),
240 '5k' => __('< 5000 Items', 'docket-cache'),
241 '10k' => __('< 10000 Items', 'docket-cache'),
242 'all' => __('> All Items', 'docket-cache'),
243 ] as $k => $n) {
244 echo '<option value="'.$k.'"'.($sort_sm === $k ? ' selected' : '').'>'.$n.'</option>';
245 }
246 ?>
247 </select>
248 </form>
249 </div>
250
251 <?php if ($opcache_view->get_pagination_arg('total_pages') > 1 || !empty($_GET['s'])) : ?>
252 <div class="box-right">
253 <form id="search-filter" method="get" action="<?php echo esc_url($this->pt->get_page()); ?>">
254 <input type="hidden" name="page" value="docket-cache-opcviewer">
255 <input type="hidden" name="idx" value="opcviewer">
256 <input type="hidden" name="sf" value="<?php echo esc_attr($sort_sf); ?>">
257 <input type="hidden" name="sm" value="<?php echo esc_attr($sort_sm); ?>">
258 <?php $opcache_view->search_box(__('Filter Cached Files', 'docket-cache'), 'opclist-info'); ?>
259 </form>
260 </div>
261 <?php endif; ?>
262 <div class="table-responsive">
263 <?php $opcache_view->display(); ?>
264 </div>
265 </div>
266 <?php endif; // is_object?>
267 <?php endif; // is_conf?>
268 </div>
269 </div>
270 </div>
271 <?php
272 if (!empty($_GET['orderby']) || !empty($_GET['paged']) || !empty($_GET['sf'])) :
273 ?>
274 <script>
275 var el = document.getElementById( "scrollmark" );
276 el.scrollIntoView( {
277 block: "start"
278 } );
279
280 </script>
281 <?php
282 endif;
283