aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2024-08-27 09:02:05 +0200
committerJulius Härtl <jus@bitgrid.net>2024-08-27 10:45:32 +0200
commitf3419c5f57166a68fdbaca8613b6ed3f0cf32d25 (patch)
treec6752ba74911ed1f5c606cfe1c25247e904c6647 /apps
parentead3f66379f35e42c2d5433eeca911b61a9cd968 (diff)
downloadnextcloud-server-f3419c5f57166a68fdbaca8613b6ed3f0cf32d25.tar.gz
nextcloud-server-f3419c5f57166a68fdbaca8613b6ed3f0cf32d25.zip
feat(settings): Add setup check for apcu cache expunge
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php1
-rw-r--r--apps/settings/composer/composer/autoload_static.php1
-rw-r--r--apps/settings/lib/AppInfo/Application.php2
-rw-r--r--apps/settings/lib/SetupChecks/PhpApcuConfig.php70
4 files changed, 74 insertions, 0 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index 41f70c3a8e6..7a3618ecb51 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -108,6 +108,7 @@ return array(
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => $baseDir . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
'OCA\\Settings\\SetupChecks\\OcxProviders' => $baseDir . '/../lib/SetupChecks/OcxProviders.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
+ 'OCA\\Settings\\SetupChecks\\PhpApcuConfig' => $baseDir . '/../lib/SetupChecks/PhpApcuConfig.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index 4fa905b55bb..18882ed9fc2 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -123,6 +123,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
'OCA\\Settings\\SetupChecks\\OcxProviders' => __DIR__ . '/..' . '/../lib/SetupChecks/OcxProviders.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
+ 'OCA\\Settings\\SetupChecks\\PhpApcuConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpApcuConfig.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 80420cb3335..a9b1a5c1d67 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -50,6 +50,7 @@ use OCA\Settings\SetupChecks\MimeTypeMigrationAvailable;
use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
use OCA\Settings\SetupChecks\OcxProviders;
use OCA\Settings\SetupChecks\OverwriteCliUrl;
+use OCA\Settings\SetupChecks\PhpApcuConfig;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
@@ -186,6 +187,7 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpDisabledFunctions::class);
$context->registerSetupCheck(PhpFreetypeSupport::class);
+ $context->registerSetupCheck(PhpApcuConfig::class);
$context->registerSetupCheck(PhpGetEnv::class);
$context->registerSetupCheck(PhpMemoryLimit::class);
$context->registerSetupCheck(PhpModules::class);
diff --git a/apps/settings/lib/SetupChecks/PhpApcuConfig.php b/apps/settings/lib/SetupChecks/PhpApcuConfig.php
new file mode 100644
index 00000000000..c91a8cefec1
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/PhpApcuConfig.php
@@ -0,0 +1,70 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Settings\SetupChecks;
+
+use OC\Memcache\APCu;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class PhpApcuConfig implements ISetupCheck {
+ public const USAGE_RATE_WARNING = 90;
+ public const AGE_WARNING = 3600 * 8;
+
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'php';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('PHP APCu configuration');
+ }
+
+ public function run(): SetupResult {
+ $localIsApcu = ltrim($this->config->getSystemValueString('memcache.local'), '\\') === APCu::class;
+ $distributedIsApcu = ltrim($this->config->getSystemValueString('memcache.distributed'), '\\') === APCu::class;
+ if (!$localIsApcu && !$distributedIsApcu) {
+ return SetupResult::success();
+ }
+
+ if (!APCu::isAvailable()) {
+ return SetupResult::success();
+ }
+
+ $cache = apcu_cache_info(true);
+ $mem = apcu_sma_info(true);
+ if ($cache === false || $mem === false) {
+ return SetupResult::success();
+ }
+
+ $expunges = $cache['expunges'];
+ $memSize = $mem['num_seg'] * $mem['seg_size'];
+ $memAvailable = $mem['avail_mem'];
+ $memUsed = $memSize - $memAvailable;
+ $usageRate = round($memUsed / $memSize * 100, 0);
+ $elapsed = max(time() - $cache['start_time'], 1);
+
+ if ($expunges > 0 && $elapsed < self::AGE_WARNING) {
+ return SetupResult::warning($this->l10n->t('Your APCu cache has been running full, consider increasing the apc.shm_size php setting.'));
+ }
+
+ if ($usageRate > self::USAGE_RATE_WARNING) {
+ return SetupResult::warning($this->l10n->t('Your APCu cache is almost full at %s%%, consider increasing the apc.shm_size php setting.', [$usageRate]));
+ }
+
+ return SetupResult::success();
+ }
+}