You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do OPcache recommendations based on actual cache usage
The current OPcache recommendations match the PHP defaults, but the values are much higher than what is required to run Nextcloud, even with a high number of installed apps. On the other hand, when other applications use the same PHP server/pool, hence the same OPcache instance, the recommended values might not be sufficient. Accurate recommendations can only be done when taking into account the actual OPcache usage.
With this commit, warnings are shown when used values exceed 90% of max values, and the recommendations are to raise the config value, showing what is currently applied.
Signed-off-by: MichaIng <micha@dietpi.com>
if (!$this->iniGetWrapper->getBool('opcache.enable')) {
434
-
returnfalse;
435
-
}
436
+
$recommendations[] = 'OPcache is disabled. For better performance, it is recommended to apply <code>opcache.enable=1</code> to your PHP configuration.';
436
437
437
-
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
438
-
returnfalse;
439
-
}
438
+
// Check for saved comments only when OPcache is currently disabled. If it was enabled, opcache.save_comments=0 would break Nextcloud in the first place.
439
+
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
440
+
$recommendations[] = 'OPcache is configured to remove code comments. With OPcache enabled, <code>opcache.save_comments=1</code> must be set for Nextcloud to function.';
441
+
}
440
442
441
-
if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
442
-
returnfalse;
443
-
}
443
+
// Compare max values with used values and warn if more than 90% is used.
444
+
} else {
445
+
// Mute error when opcache.restrict_api is set and does not permit Nextcloud to use opcache_get_status(). All below conditions will then return false.
446
+
// ToDo: Add a check for opcache.restrict_api, since it can cause issues when Nextcloud cannot evict cached scripts: https://github.com/nextcloud/server/pull/8188
447
+
$status = @opcache_get_status();
444
448
445
-
if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
446
-
returnfalse;
447
-
}
449
+
if ($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys'] > 0.9) {
450
+
$recommendations[] = 'The maximum number of OPcache keys is nearly exceeded. To assure that all scripts can be hold in cache, it is recommended to apply <code>opcache.max_accelerated_files</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') ?: 'currently') . '</code>.';
451
+
}
448
452
449
-
if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
450
-
returnfalse;
453
+
if ($status['memory_usage']['used_memory'] / $status['memory_usage']['free_memory'] > 9) {
454
+
$recommendations[] = 'The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply <code>opcache.memory_consumption</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') ?: 'currently') . '</code>.';
455
+
}
456
+
457
+
if ($status['interned_strings_usage']['used_memory'] / $status['interned_strings_usage']['free_memory'] > 9) {
458
+
$recommendations[] = 'The OPcache interned strings buffer is nearly full. To assure that repeating strings can be effectively cached, it is recommended to apply <code>opcache.interned_strings_buffer</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') ?: 'currently') . '</code>.';
msg: t('core','The PHP OPcache module is not properly configured. {linkstart}For better performance it is recommended ↗{linkend} to use the following settings in the <code>php.ini</code>:')
msg: 'The PHP OPcache module is not properly configured. <a target="_blank" rel="noreferrer noopener" class="external" href="https://example.org/link/to/doc">For better performance it is recommended ↗</a> to use the following settings in the <code>php.ini</code>:'+"<pre><code>opcache.enable=1\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=10000\nopcache.memory_consumption=128\nopcache.save_comments=1\nopcache.revalidate_freq=1</code></pre>",
825
+
msg: 'The PHP OPcache module is not properly configured:<ul><li>recommendation1</li><li>recommendation2</li></ul>',
0 commit comments