From 755381a4c2859c6558e43ccaf2a793e6d680b3fc Mon Sep 17 00:00:00 2001 From: MichaIng Date: Fri, 7 Jan 2022 19:43:07 +0100 Subject: [PATCH] Avoid zero division in setup checks Fixes: https://github.com/nextcloud/server/issues/30532 Signed-off-by: MichaIng --- .../lib/Controller/CheckSetupController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 78874fd02b07f..ac734e5eb780f 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -492,15 +492,24 @@ protected function getOpcacheSetupRecommendations(): array { $status = opcache_get_status(false); // Recommend to raise value, if more than 90% of max value is reached - if ($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys'] > 0.9) { + if ( + empty($status['opcache_statistics']['max_cached_keys']) || + ($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys'] > 0.9) + ) { $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 opcache.max_accelerated_files to your PHP configuration with a value higher than ' . ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') ?: 'currently') . '.'; } - if ($status['memory_usage']['used_memory'] / $status['memory_usage']['free_memory'] > 9) { + if ( + empty($status['memory_usage']['free_memory']) || + ($status['memory_usage']['used_memory'] / $status['memory_usage']['free_memory'] > 9) + ) { $recommendations[] = 'The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply opcache.memory_consumption to your PHP configuration with a value higher than ' . ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') ?: 'currently') . '.'; } - if ($status['interned_strings_usage']['used_memory'] / $status['interned_strings_usage']['free_memory'] > 9) { + if ( + empty($status['interned_strings_usage']['free_memory']) || + ($status['interned_strings_usage']['used_memory'] / $status['interned_strings_usage']['free_memory'] > 9) + ) { $recommendations[] = 'The OPcache interned strings buffer is nearly full. To assure that repeating strings can be effectively cached, it is recommended to apply opcache.interned_strings_buffer to your PHP configuration with a value higher than ' . ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') ?: 'currently') . '.'; } }