PluginProbe
phpinfo() WP – Site Health, PHP Compatibility & Server Audit / 7.2.5
phpinfo() WP – Site Health, PHP Compatibility & Server Audit v7.2.5
7.2.7 7.2.6 7.2.5 7.2.4 7.2.3 7.2.0 7.2.1 7.2.2 7.1.0 7.0.3 7.0.4 7.0.5 trunk 6.0 7.0.0 7.0.1 7.0.2
phpinfo-wp / views / pro / opcache.php

opcache.php in phpinfo() WP – Site Health, PHP Compatibility & Server Audit 7.2.5, at views/pro/opcache.php

148 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die('Unauthorized Access');
3
4 if (!Phpinfo_WP_License::is_valid()) {
5 phpinfowp_render_feature_lock([
6 'feature' => 'OPcache Dashboard',
7 'icon' => 'dashicons-performance',
8 'tagline' => 'Hit rate, memory footprint, cached scripts count — and a one-click cache flush button.',
9 'previews' => [
10 'Status: <strong>Enabled</strong>',
11 'Hit rate: <strong>— %</strong>',
12 'Memory used: <strong>— MB / — MB</strong>',
13 'Cached scripts: <strong>—</strong>',
14 ],
15 ]);
16 return;
17 }
18
19 $message = '';
20 $msg_type = 'success';
21
22 if (isset($_POST['phpinfowp_opcache_reset']) && check_admin_referer('phpinfowp_opcache_nonce')) {
23 $ok = Phpinfo_WP_OPcache::reset();
24 $message = $ok ? 'OPcache cleared successfully.' : 'Could not clear OPcache — function not available.';
25 $msg_type = $ok ? 'success' : 'error';
26 }
27
28 $s = Phpinfo_WP_OPcache::status();
29 ?>
30
31 <div class="phpinfowp-pro-page">
32 <div class="phpinfowp-page-header">
33 <div>
34 <h1>OPcache Dashboard <span class="phpinfowp-pro-badge"><?php _e('PRO', 'phpinfo-wp'); ?></span></h1>
35 <p class="phpinfowp-page-subtitle"><?php _e('Check OPcache memory usage, hit rates, and list cached scripts.', 'phpinfo-wp'); ?></p>
36 </div>
37 </div>
38
39 <?php if ($message): ?>
40 <div class="notice notice-<?php echo $msg_type; ?> inline is-dismissible"><p><?php echo esc_html($message); ?></p></div>
41 <?php endif; ?>
42
43 <?php if (!Phpinfo_WP_OPcache::is_available()): ?>
44 <div class="notice notice-warning inline">
45 <p><strong><?php _e('OPcache is not available', 'phpinfo-wp'); ?></strong> on this server. Ask your host to enable the <code>opcache</code> PHP extension it's free and can cut PHP CPU usage by 50–80%.</p>
46 </div>
47 <?php elseif (!$s || !$s['enabled']): ?>
48 <div class="notice notice-warning inline">
49 <p><strong><?php _e('OPcache extension is installed but disabled.', 'phpinfo-wp'); ?></strong> Enable it in <code>php.ini</code>: <code>opcache.enable=1</code></p>
50 </div>
51 <?php else: ?>
52
53 <!-- Hit rate card -->
54 <div class="phpinfowp-opcache-grid">
55 <div class="phpinfowp-opcache-card phpinfowp-opcache-hitrate">
56 <div class="phpinfowp-grade-circle <?php echo esc_attr(Phpinfo_WP_OPcache::hit_rate_class($s['hit_rate'] ?? 0)); ?>">
57 <?php echo $s['hit_rate'] !== null ? esc_html($s['hit_rate']) . '%' : 'N/A'; ?>
58 </div>
59 <div>
60 <h3 style="margin:0 0 4px"><?php _e('Hit Rate', 'phpinfo-wp'); ?></h3>
61 <p style="margin:0;color:#666;font-size:13px">
62 <?php echo number_format($s['hits']); ?> hits /
63 <?php echo number_format($s['misses']); ?> misses
64 </p>
65 <?php if ($s['full']): ?>
66 <p style="color:#d63638;margin:6px 0 0;font-size:13px">
67 Cache is full — increase <code>opcache.memory_consumption</code>
68 </p>
69 <?php endif; ?>
70 </div>
71 </div>
72
73 <div class="phpinfowp-opcache-card">
74 <h3 style="margin-top:0"><?php _e('Memory Usage', 'phpinfo-wp'); ?></h3>
75 <div class="phpinfowp-progress-bar-wrap">
76 <div class="phpinfowp-progress-bar" style="width:<?php echo min(100, $s['memory_pct']); ?>%;background:<?php echo $s['memory_pct'] > 85 ? '#d63638' : '#777BB3'; ?>"></div>
77 </div>
78 <p style="margin:6px 0 0;font-size:13px;color:#444">
79 Used: <strong><?php echo esc_html(Phpinfo_WP_OPcache::format_bytes($s['memory_used'])); ?></strong>
80 / Total: <?php echo esc_html(Phpinfo_WP_OPcache::format_bytes($s['memory_total'])); ?>
81 &nbsp;&middot;&nbsp; Wasted: <?php echo esc_html(Phpinfo_WP_OPcache::format_bytes($s['memory_wasted'])); ?>
82 (<?php echo round($s['wasted_pct'], 1); ?>%)
83 </p>
84 </div>
85
86 <div class="phpinfowp-opcache-card">
87 <h3 style="margin-top:0"><?php _e('Cached Scripts', 'phpinfo-wp'); ?></h3>
88 <div class="phpinfowp-progress-bar-wrap">
89 <?php $script_pct = $s['max_scripts'] > 0 ? round($s['cached_scripts'] / $s['max_scripts'] * 100, 1) : 0; ?>
90 <div class="phpinfowp-progress-bar" style="width:<?php echo min(100, $script_pct); ?>%;background:<?php echo $script_pct > 90 ? '#d63638' : '#00a32a'; ?>"></div>
91 </div>
92 <p style="margin:6px 0 0;font-size:13px;color:#444">
93 <strong><?php echo number_format($s['cached_scripts']); ?></strong>
94 / <?php echo number_format($s['max_scripts']); ?> max
95 (<?php echo $script_pct; ?>%)
96 </p>
97 <?php if ($s['start_time']): ?>
98 <p style="margin:6px 0 0;font-size:12px;color:#666">
99 Running since: <?php echo esc_html(gmdate('Y-m-d H:i', $s['start_time'])); ?> UTC
100 </p>
101 <?php endif; ?>
102 </div>
103 </div>
104
105 <!-- Key directives -->
106 <h2 style="margin-top:28px"><?php _e('Key Directives', 'phpinfo-wp'); ?></h2>
107 <table class="wp-list-table widefat fixed striped" style="max-width:700px">
108 <thead><tr><th><?php _e('Directive', 'phpinfo-wp'); ?></th><th><?php _e('Value', 'phpinfo-wp'); ?></th></tr></thead>
109 <tbody>
110 <?php
111 $show = [
112 'opcache.enable', 'opcache.memory_consumption', 'opcache.max_accelerated_files',
113 'opcache.validate_timestamps', 'opcache.revalidate_freq', 'opcache.save_comments',
114 'opcache.enable_cli', 'opcache.jit', 'opcache.jit_buffer_size',
115 ];
116 foreach ($show as $d):
117 $val = $s['directives'][$d] ?? ini_get($d);
118 if ($val === false || $val === null) continue;
119 ?>
120 <tr>
121 <td><code><?php echo esc_html($d); ?></code></td>
122 <td><?php echo esc_html((string)$val); ?></td>
123 </tr>
124 <?php endforeach; ?>
125 </tbody>
126 </table>
127
128 <!-- Reset button -->
129 <?php
130 $reset_disabled = !function_exists('opcache_reset') || strpos(ini_get('disable_functions'), 'opcache_reset') !== false;
131 $restrict_api = ini_get('opcache.restrict_api');
132 $is_restricted = $restrict_api && stripos(__FILE__, $restrict_api) !== 0;
133 ?>
134 <form method="post" style="margin-top:20px" onsubmit="return confirm('Clear OPcache? PHP will recompile all files on next request.')">
135 <?php wp_nonce_field('phpinfowp_opcache_nonce'); ?>
136 <input type="hidden" name="phpinfowp_opcache_reset" value="1">
137 <button type="submit" class="button button-secondary" <?php if ($reset_disabled || $is_restricted) echo 'disabled'; ?>>Clear OPcache</button>
138 <span style="margin-left:8px;font-size:12px;color:#666"><?php _e('Forces recompilation of all cached PHP files.', 'phpinfo-wp'); ?></span>
139 <?php if ($reset_disabled): ?>
140 <p style="color:#d63638;font-size:12px;margin-top:8px">⚠️ <strong><?php _e('Clear OPcache disabled:', 'phpinfo-wp'); ?></strong> Your host has added <code>opcache_reset</code> to the PHP <code>disable_functions</code> list.</p>
141 <?php elseif ($is_restricted): ?>
142 <p style="color:#d63638;font-size:12px;margin-top:8px">⚠️ <strong><?php _e('Clear OPcache disabled:', 'phpinfo-wp'); ?></strong> Your host has restricted OPcache API access via <code>opcache.restrict_api</code>.</p>
143 <?php endif; ?>
144 </form>
145
146 <?php endif; ?>
147 </div>
148