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
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.
The checks whether the module is loaded and whether the OPcache is properly configured have been merged into a single function. This allowed to reduce the overhead of OPcache configuration checks when the module is not loaded.
A check has been added whether Nextcloud is permitted to use the OPcache API. Without this, inconsistencies during core or app upgrades may cause errors and OPcache usage cannot be determined for the new usage based checks.
OPcache usage based checks are skipped when Nextcloud is not permitted to use the API.
Signed-off-by: MichaIng <micha@dietpi.com>
// If the module is not loaded, return directly to skip inapplicable checks
442
+
if (!extension_loaded('Zend OPcache')) {
443
+
return ['The PHP OPcache module is not loaded. <a target="_blank" rel="noreferrer noopener" class="external" href="' . $this->urlGenerator->linkToDocs('admin-php-opcache') . '">For better performance it is recommended</a> to load it into your PHP installation.'];
442
444
}
443
445
444
-
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
445
-
returnfalse;
446
-
}
446
+
$recommendations = [];
447
447
448
-
if ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
449
-
returnfalse;
448
+
// Check whether Nextcloud is allowed to use the OPcache API
if (isset($permittedPath) && $permittedPath !== '' && !str_starts_with(\OC::$SERVERROOT, $permittedPath)) {
452
+
$isPermitted = false;
450
453
}
451
454
452
-
if ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') < 128) {
453
-
returnfalse;
454
-
}
455
+
if (!$this->iniGetWrapper->getBool('opcache.enable')) {
456
+
$recommendations[] = 'OPcache is disabled. For better performance, it is recommended to apply <code>opcache.enable=1</code> to your PHP configuration.';
455
457
456
-
if ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
457
-
returnfalse;
458
+
// 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.
459
+
if (!$this->iniGetWrapper->getBool('opcache.save_comments')) {
460
+
$recommendations[] = 'OPcache is configured to remove code comments. With OPcache enabled, <code>opcache.save_comments=1</code> must be set for Nextcloud to function.';
461
+
}
462
+
463
+
if (!$isPermitted) {
464
+
$recommendations[] = 'Nextcloud is not allowed to use the OPcache API. With OPcache enabled, it is highly recommended to include all Nextcloud directories with <code>opcache.restrict_api</code> or unset this setting to disable OPcache API restrictions, to prevent errors during Nextcloud core or app upgrades.';
465
+
}
466
+
} elseif (!$isPermitted) {
467
+
$recommendations[] = 'Nextcloud is not allowed to use the OPcache API. It is highly recommended to include all Nextcloud directories with <code>opcache.restrict_api</code> or unset this setting to disable OPcache API restrictions, to prevent errors during Nextcloud core or app upgrades.';
468
+
} else {
469
+
// Check whether opcache_get_status has been explicitly disabled an in case skip usage based checks
if (isset($disabledFunctions) && str_contains($disabledFunctions, 'opcache_get_status')) {
472
+
return [];
473
+
}
474
+
475
+
$status = opcache_get_status(false);
476
+
477
+
// Recommend to raise value, if more than 90% of max value is reached
478
+
if ($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys'] > 0.9) {
479
+
$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>.';
480
+
}
481
+
482
+
if ($status['memory_usage']['used_memory'] / $status['memory_usage']['free_memory'] > 9) {
483
+
$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>.';
484
+
}
485
+
486
+
if ($status['interned_strings_usage']['used_memory'] / $status['interned_strings_usage']['free_memory'] > 9) {
487
+
$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>.';
488
+
}
458
489
}
459
490
460
-
returntrue;
491
+
return$recommendations;
461
492
}
462
493
463
494
/**
@@ -557,10 +588,6 @@ protected function getCronErrors() {
Copy file name to clipboardExpand all lines: core/js/setupchecks.js
+8-10Lines changed: 8 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -322,18 +322,16 @@
322
322
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
323
323
});
324
324
}
325
-
if(!data.hasOpcacheLoaded){
326
-
messages.push({
327
-
msg: t('core','The PHP OPcache module is not loaded. {linkstart}For better performance it is recommended ↗{linkend} to load it into your PHP installation.')
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>",
837
-
type: OC.SetupChecks.MESSAGE_TYPE_INFO
838
-
}]);
839
-
done();
840
-
});
841
-
});
842
-
843
-
it('should return an info if server has no opcache at all',function(done){
msg: 'The PHP OPcache module is not loaded. <a target="_blank" rel="noreferrer noopener" class="external" href="https://example.org/link/to/doc">For better performance it is recommended ↗</a> to load it into your PHP installation.',
825
+
msg: 'The PHP OPcache module is not properly configured:<ul><li>recommendation1</li><li>recommendation2</li></ul>',
0 commit comments