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 required to run Nextcloud, even with a high number of installed apps. On the other hand, when other applications use the same OPcache instance, the recommended values might not be sufficient. Accurate recommendations need to take into account actual OPcache usage.
With this commit, recommendations are shown to raise the config value if more than 90% of max cache size or number of keys is used.
Signed-off-by: MichaIng <micha@dietpi.com>
if (!$this->iniGetWrapper->getBool('opcache.enable')) {
434
-
returnfalse;
435
-
}
437
+
$recommendations[] = 'OPcache is disabled. For better performance, it is recommended to apply <code>opcache.enable=1</code> to your PHP configuration.';
436
438
437
-
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
438
-
returnfalse;
439
-
}
439
+
// 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.
440
+
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
441
+
$recommendations[] = 'OPcache is configured to remove code comments. With OPcache enabled, <code>opcache.save_comments=1</code> must be set for Nextcloud to function.';
442
+
}
443
+
} else {
444
+
// 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.
445
+
// 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
446
+
$status = @opcache_get_status(false);
440
447
441
-
if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
442
-
returnfalse;
443
-
}
448
+
// Recommend to raise value, if more than 90% of max value is reached
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
+
}
444
452
445
-
if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
446
-
returnfalse;
447
-
}
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
+
}
448
456
449
-
if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
450
-
returnfalse;
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