|
1 | 1 | # Magento 2 OPcache GUI PHP Performance Dashboard |
2 | 2 |
|
3 | | -Magento 2 Opcache Control GUI using React Frontend Micro-services (https://github.com/amnuts/opcache-gui). |
| 3 | +[](https://github.com/amadeco/module-opcache-gui) |
| 4 | +[](https://magento.com) |
| 5 | +[](https://www.php.net) |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +> Advanced OPcache monitoring and control GUI for Magento 2, implemented with React for a responsive and modern experience (https://github.com/amnuts/opcache-gui). |
4 | 9 |
|
5 | 10 | <img width="1374" height="937" alt="Capture d’écran 2025-08-19 à 20 51 57" src="https://github.com/user-attachments/assets/df8ff91d-d4af-462e-85bd-ee851a1a57cb" /> |
6 | 11 |
|
7 | | -## Where to find in the Admin Menu |
| 12 | +## Features |
| 13 | + |
| 14 | +- **Real-time OPcache Monitoring**: View memory usage, hit/miss ratio, and cached scripts |
| 15 | +- **Performance Metrics**: Track OPcache efficiency and PHP performance |
| 16 | +- **Cache Control**: Reset cache, invalidate files, or force file refresh |
| 17 | +- **Configuration Viewer**: Examine your current OPcache configuration |
| 18 | +- **React-based Interface**: Modern, responsive UI built with React |
| 19 | +- **Script Analysis**: Identify which files consume the most cache memory |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +### Option 1: Composer (Recommended) |
| 24 | + |
| 25 | +```bash |
| 26 | +composer require amadeco/module-opcache-gui |
| 27 | +bin/magento module:enable Amadeco_OpcacheGui |
| 28 | +bin/magento setup:upgrade --keep-generated |
| 29 | +bin/magento cache:clean |
| 30 | +``` |
| 31 | + |
| 32 | +> This extension uses CDN-hosted React components and doesn't require static content generation, allowing installation with the `--keep-generated` flag. |
| 33 | +
|
| 34 | +### Option 2: Manual Installation |
| 35 | + |
| 36 | +1. Download or clone the repository |
| 37 | +2. Copy the files to `app/code/Amadeco/OpcacheGui/` |
| 38 | +3. Run the following commands: |
| 39 | + |
| 40 | +```bash |
| 41 | +bin/magento module:enable Amadeco_OpcacheGui |
| 42 | +bin/magento setup:upgrade --keep-generated |
| 43 | +bin/magento cache:clean |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +### Accessing the Dashboard |
| 49 | + |
| 50 | +Navigate to **System → React → PHP OpCache Dashboard** in your Magento Admin Panel. |
| 51 | + |
| 52 | +## OPcache Optimization Guide |
8 | 53 |
|
9 | | -System -> Tools -> OpCache GUI |
| 54 | +### Recommended PHP OPcache Settings for Magento 2 |
10 | 55 |
|
11 | | -## Installation |
| 56 | +```ini |
| 57 | +opcache.enable = 1 |
| 58 | +opcache.enable_cli = 0 |
| 59 | +opcache.memory_consumption = 1024 |
| 60 | +opcache.interned_strings_buffer = 128 |
| 61 | +opcache.max_accelerated_files = 60000 |
| 62 | +; |
| 63 | +; Production Mode |
| 64 | +; |
| 65 | +opcache.validate_timestamps = 0 |
| 66 | +; |
| 67 | +; Development Mode |
| 68 | +; |
| 69 | +;opcache.validate_timestamps = 1 |
| 70 | +;opcache.revalidate_freq = 10 |
| 71 | +; |
| 72 | +opcache.save_comments = 1 |
| 73 | +opcache.enable_file_override = 0 |
| 74 | +``` |
12 | 75 |
|
13 | | -Copy to App code, Setup, and compile as always. |
| 76 | +### Technical Tips |
14 | 77 |
|
15 | | -This Extension doesn't need static content generation it uses CDN version of React JS. So, you can install with flag *--keep-generated* |
| 78 | +#### Tip 1: Calculate Your Required Cache Size |
16 | 79 |
|
17 | | -or use composer: |
| 80 | +```bash |
| 81 | +# Calculate the exact number of PHP files in your Magento codebase |
| 82 | +find . -type f -print | grep php | wc -l |
18 | 83 | ``` |
19 | | -composer require amadeco/module-db-override |
| 84 | + |
| 85 | +Set `opcache.max_accelerated_files` to this number plus a 25% margin, rounded to the nearest higher prime number for optimal hash table performance. |
| 86 | + |
| 87 | +#### Tip 2: Implement Selective PHP Preloading |
| 88 | + |
| 89 | +For Magento 2, selective preloading is vastly more efficient than preloading all files: |
| 90 | + |
| 91 | +```php |
| 92 | +// Example preload.php for Magento 2 |
| 93 | +function preload($path) { |
| 94 | + static $loaded = 0; |
| 95 | + if ($loaded >= 500) return; |
| 96 | + |
| 97 | + if (is_file($path) && preg_match("/\.php$/", $path)) { |
| 98 | + opcache_compile_file($path); |
| 99 | + $loaded++; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Only preload essential core files |
| 104 | +preload(__DIR__ . '/vendor/magento/framework/App/Bootstrap.php'); |
| 105 | +preload(__DIR__ . '/vendor/magento/framework/App/Http.php'); |
| 106 | +// Additional critical files... |
20 | 107 | ``` |
21 | 108 |
|
22 | | -## Magento 2 Opcache best settings |
| 109 | +References: |
| 110 | +- [Magento Community Issue #98](https://github.com/magento/community-features/issues/98#issuecomment-481635316) |
| 111 | +- [Example Implementation](https://github.com/MonogoPolska/monogo-m2-preload) |
| 112 | + |
| 113 | +#### Tip 3: Avoid JIT Compilation for Magento 2 |
| 114 | + |
| 115 | +JIT compilation causes segfaults with Magento 2 and provides minimal performance gains: |
| 116 | + |
| 117 | +```ini |
| 118 | +; Disable JIT for Magento 2 |
| 119 | +opcache.jit_buffer_size = 0 |
| 120 | +opcache.jit = off |
| 121 | +``` |
| 122 | + |
| 123 | +Reference: [Magento 2 PHP 8.2 JIT Performance Analysis](https://yegorshytikov.medium.com/magento-2-adobe-commerce-php-8-2-jit-performance-how-faster-is-magento-2-with-jit-876bdb8641a1) |
| 124 | + |
| 125 | +#### Tip 4: Blacklist Non-Essential Files |
23 | 126 |
|
24 | | -The biggest Magento 2 performance issue is the wrong (default) PHP OPcache settings. |
| 127 | +Create an `opcache.blacklist` file to exclude test directories and rarely-used files: |
25 | 128 |
|
26 | | -Check your PHP settings with this module: |
27 | 129 | ``` |
| 130 | +/home/USER/public_html/vendor/*/Test/* |
| 131 | +/home/USER/public_html/vendor/*/tests/* |
| 132 | +/home/USER/public_html/dev/* |
| 133 | +/home/USER/public_html/setup/* |
| 134 | +``` |
| 135 | + |
| 136 | +Then reference it in your php.ini or pool configuration: |
| 137 | +```ini |
| 138 | +opcache.blacklist_filename = /path/to/opcache.blacklist |
| 139 | +``` |
| 140 | + |
| 141 | +#### Tip 5: Separate CLI and Web Process Configurations |
| 142 | + |
| 143 | +For optimal performance, maintain distinct OPcache configurations for CLI and web processes: |
| 144 | + |
| 145 | +**CLI Configuration** (`/etc/php/8.x/cli/php.ini`): |
| 146 | +```ini |
| 147 | +; |
| 148 | +; OpCache Config |
| 149 | +; |
| 150 | +opcache.enable = 1 |
| 151 | +opcache.enable_cli = 1 |
| 152 | +opcache.memory_consumption = 512 |
| 153 | +opcache.interned_strings_buffer = 32 |
| 154 | +opcache.max_accelerated_files = 30000 |
| 155 | +opcache.max_wasted_percentage = 5 |
| 156 | +opcache.use_cwd = 1 |
| 157 | +; |
| 158 | +; Magento mode Production |
| 159 | +; |
| 160 | +;opcache.validate_timestamps = 0 |
| 161 | +; |
| 162 | +; Magento mode Developpement |
| 163 | +; |
| 164 | +opcache.validate_timestamps = 1 |
| 165 | +;opcache.revalidate_freq = 10 |
| 166 | +opcache.file_update_protection = 0 |
| 167 | +opcache.revalidate_path = 0 |
| 168 | +opcache.save_comments = 1 |
| 169 | +opcache.load_comments = 1 |
| 170 | +opcache.enable_file_override = 0 |
| 171 | +opcache.optimization_level = 0xffffffff |
| 172 | +opcache.blacklist_filename = "/home/**USER**/opcache.blacklist" |
| 173 | +opcache.max_file_size = 0 |
| 174 | +opcache.consistency_checks = 0 |
| 175 | +opcache.force_restart_timeout = 60 |
| 176 | +opcache.error_log = "/var/log/php-fpm/opcache.log" |
| 177 | +;opcache.log_verbosity_level = 1 |
| 178 | +opcache.log_verbosity_level = 3 |
| 179 | +opcache.preferred_memory_model = "" |
| 180 | +opcache.protect_memory = 0 |
| 181 | +; |
| 182 | +; |
| 183 | +; |
| 184 | +opcache.file_cache = "/tmp/" |
| 185 | +opcache.file_cache_only = 1 |
| 186 | +opcache.file_cache_consistency_checks = 1 |
| 187 | +opcache.huge_code_pages = 1 |
| 188 | +; |
| 189 | +; Support for PHP >7.4 Preload Feature #98 |
| 190 | +; |
| 191 | +; Issue : https://github.com/magento/community-features/issues/98#issuecomment-481635316 |
| 192 | +; Magento 2 simple preload : https://github.com/MonogoPolska/monogo-m2-preload |
| 193 | +; |
| 194 | +; Doesn't work in CLI with config opcache.file_cache_only = 1 |
| 195 | +; |
| 196 | +;opcache.preload = "/home/**USER**/public_html/preload.php" |
| 197 | +;opcache.preload_user = **PHP-USER** |
| 198 | +; |
| 199 | +; JIT Just In Time Compilation |
| 200 | +; |
| 201 | +;opcache.jit = 1235 |
| 202 | +;opcache.jit_buffer_size = 536870912 |
| 203 | +opcache.jit = off |
| 204 | +opcache.jit_buffer_size = 0 |
| 205 | +``` |
| 206 | + |
| 207 | +**Web Processes Configuration** (`/etc/php/8.x/fpm/php.ini`): |
| 208 | +```ini |
| 209 | +; |
| 210 | +; OpCache Config |
| 211 | +; |
28 | 212 | opcache.enable = 1 |
29 | 213 | opcache.enable_cli = 0 |
30 | | -opcache.memory_consumption = 556 |
31 | | -opcache.max_accelerated_files = 1000000 |
| 214 | +opcache.use_cwd = 1 |
| 215 | +opcache.validate_root = 1 |
| 216 | +opcache.revalidate_path = 0 |
| 217 | +; |
| 218 | +; Magento mode Production |
| 219 | +; |
32 | 220 | opcache.validate_timestamps = 0 |
33 | | -opcache.interned_strings_buffer=64 |
34 | | -opcache.max_wasted_percentage=5 |
35 | | -opcache.save_comments=1 |
36 | | -opcache.fast_shutdown=1 |
37 | | -``` |
38 | | - |
39 | | -## CLI opcache settings |
40 | | -should be a separate cli config file like */etc/php/8.1/cli/conf.d/10-opcache.ini* |
41 | | -``` |
42 | | -zend_extension=opcache.so |
43 | | -opcache.memory_consumption=1000M |
44 | | -opcache.interned_strings_buffer=8 |
45 | | -opcache.max_accelerated_files=10000000 |
46 | | -opcache.validate_timestamps=1 |
47 | | -; opcache.revalidate_freq=2 |
48 | | -opcache.enable_cli=1 |
49 | | -opcache.file_cache=/tmp/ |
50 | | -opcache.file_cache_only=0 |
51 | | -opcache.file_cache_consistency_checks=1 |
52 | | -``` |
| 221 | +; |
| 222 | +; Magento mode Developpement |
| 223 | +; |
| 224 | +;opcache.validate_timestamps = 1 |
| 225 | +;opcache.revalidate_freq = 10 |
| 226 | +opcache.save_comments = 1 |
| 227 | +opcache.enable_file_override = 0 |
| 228 | +opcache.consistency_checks = 0 |
| 229 | +opcache.protect_memory = 0 |
| 230 | +opcache.memory_consumption = 1024 |
| 231 | +opcache.interned_strings_buffer = 256 |
| 232 | +; |
| 233 | +; Quickly calculate the number of files in our codebase. |
| 234 | +; find . -type f -print | grep php | wc -l |
| 235 | +; |
| 236 | +opcache.max_accelerated_files = 120000 |
| 237 | +opcache.max_wasted_percentage = 15 |
| 238 | +opcache.file_update_protection = 2 |
| 239 | +opcache.optimization_level = 0xffffffff |
| 240 | +;opcache.blacklist_filename = "/home/**USER**/opcache.blacklist" |
| 241 | +opcache.max_file_size = 0 |
| 242 | +opcache.force_restart_timeout = 60 |
| 243 | +opcache.error_log = "/home/**USER**/public_html/var/log/opcache.log" |
| 244 | +opcache.log_verbosity_level = 2 |
| 245 | +opcache.preferred_memory_model = "" |
| 246 | +opcache.huge_code_pages = 1 |
| 247 | +``` |
| 248 | + |
| 249 | +**Key Differences Explained**: |
| 250 | + |
| 251 | +| Setting | CLI | Web | Reason | |
| 252 | +|---------|-----|-----|--------| |
| 253 | +| `memory_consumption` | 512MB | 1024MB | CLI needs less memory since it handles one command at a time | |
| 254 | +| `interned_strings_buffer` | 32MB | 256MB | Web processes handle more unique strings from templates | |
| 255 | +| `validate_timestamps` | On | Off | CLI tools need to see file changes immediately | |
| 256 | +| `file_cache_only` | On | Off | CLI benefits from file-based cache for persistence | |
| 257 | +| `max_accelerated_files` | 30000 | 120000 | CLI uses fewer files than web processes | |
| 258 | +| `log_verbosity_level` | 3 | 2 | More detailed logging helps with CLI debugging | |
| 259 | + |
| 260 | +#### Tip 6: PHP-FPM Pool Partitioning for Frontend and Admin |
| 261 | + |
| 262 | +Split your PHP-FPM configuration into separate pools for frontend and admin: |
| 263 | + |
| 264 | +```ini |
| 265 | +# /etc/php/8.1/fpm/pool.d/magento-frontend.conf |
| 266 | +[magento-frontend] |
| 267 | +user = www-data |
| 268 | +listen = /var/run/php-fpm-magento-frontend.sock |
| 269 | +pm = dynamic |
| 270 | +pm.max_children = 120 |
| 271 | +pm.start_servers = 20 |
| 272 | +pm.min_spare_servers = 10 |
| 273 | +pm.max_spare_servers = 35 |
| 274 | + |
| 275 | +# /etc/php/8.1/fpm/pool.d/magento-admin.conf |
| 276 | +[magento-admin] |
| 277 | +user = www-data |
| 278 | +listen = /var/run/php-fpm-magento-admin.sock |
| 279 | +pm = dynamic |
| 280 | +pm.max_children = 20 |
| 281 | +pm.start_servers = 5 |
| 282 | +pm.min_spare_servers = 3 |
| 283 | +pm.max_spare_servers = 10 |
| 284 | +``` |
| 285 | + |
| 286 | +Then configure NGINX to route requests accordingly: |
| 287 | + |
| 288 | +```nginx |
| 289 | +# Frontend requests |
| 290 | +location ~ ^/(pub|static|media)/.*\.php$ { |
| 291 | + fastcgi_pass unix:/var/run/php-fpm-magento-frontend.sock; |
| 292 | + # Additional FastCGI settings... |
| 293 | +} |
| 294 | +
|
| 295 | +# Admin requests |
| 296 | +location ~ ^/admin { |
| 297 | + fastcgi_pass unix:/var/run/php-fpm-magento-admin.sock; |
| 298 | + # Additional FastCGI settings... |
| 299 | +} |
| 300 | +``` |
| 301 | + |
| 302 | +Benefits: |
| 303 | +- Better resource allocation based on specific needs |
| 304 | +- Isolation of admin processes from customer-facing frontend |
| 305 | +- Prevents admin-intensive tasks from impacting storefront performance |
| 306 | +- More efficient OPcache utilization for each context |
| 307 | + |
| 308 | +## Configuration Location Matters |
| 309 | + |
| 310 | +OPcache memory settings must be configured in php.ini rather than in PHP-FPM pool configuration files: |
| 311 | + |
| 312 | +1. **Initialization Order**: OPcache initializes early in PHP's startup process, before pool configurations are processed |
| 313 | + |
| 314 | +2. **Shared Memory Allocation**: Settings like `memory_consumption` define system-level allocations that must be consistent across PHP-FPM pools |
| 315 | + |
| 316 | +3. **Global vs. Pool-specific Settings**: Some directives only work when set globally in php.ini |
| 317 | + |
| 318 | +## Credits |
| 319 | + |
| 320 | +- Based on [Genaker/Magento2OPcacheGUI](https://github.com/Genaker/Magento2OPcacheGUI) |
| 321 | +- Integrates with [amnuts/opcache-gui](https://github.com/amnuts/opcache-gui) |
| 322 | +- Enhanced by [Amadeco](https://www.amadeco.fr) |
| 323 | + |
| 324 | +## License |
| 325 | + |
| 326 | +[MIT License](LICENSE.md) |
0 commit comments