Skip to content

Commit

Permalink
Avoid zero division in setup checks
Browse files Browse the repository at this point in the history
Fixes: #30532

Signed-off-by: MichaIng <micha@dietpi.com>
  • Loading branch information
MichaIng authored and backportbot[bot] committed Jan 11, 2022
1 parent ad5501a commit 755381a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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>.';
}

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 <code>opcache.memory_consumption</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') ?: 'currently') . '</code>.';
}

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 <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>.';
}
}
Expand Down

0 comments on commit 755381a

Please sign in to comment.