diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 93072981e9..f7ee8c73c8 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -316,6 +316,15 @@ type: OC.SetupChecks.MESSAGE_TYPE_WARNING }); } + if (!data.isTheMemoryLimitHighEnough) { + messages.push({ + msg: t( + 'core', + 'The PHP memory limit is below the recommended value of 512MB.' + ), + type: OC.SetupChecks.MESSAGE_TYPE_WARNING + }) + } } else { messages.push({ msg: t('core', 'Error occurred while checking server setup'), diff --git a/lib/private/MemoryInfo.php b/lib/private/MemoryInfo.php new file mode 100644 index 0000000000..14865ed682 --- /dev/null +++ b/lib/private/MemoryInfo.php @@ -0,0 +1,47 @@ +memoryLimitToBytes($iniValue); + } + } + + /** + * Converts the ini memory limit to bytes. + * + * @param string $memoryLimit The "memory_limit" ini value + * @return int + */ + private function memoryLimitToBytes(string $memoryLimit): int { + $last = strtolower(substr($memoryLimit, -1)); + $memoryLimit = (int)substr($memoryLimit, 0, -1); + + // intended fall trough + switch($last) { + case 'g': + $memoryLimit *= 1024; + case 'm': + $memoryLimit *= 1024; + case 'k': + $memoryLimit *= 1024; + } + + return $memoryLimit; + } +} diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index c706d6e735..eca6766747 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -39,6 +39,7 @@ use OC\DB\Connection; use OC\DB\MissingIndexInformation; use OC\IntegrityCheck\Checker; use OC\Lock\NoopLockingProvider; +use OC\MemoryInfo; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; @@ -81,6 +82,8 @@ class CheckSetupController extends Controller { private $lockingProvider; /** @var IDateTimeFormatter */ private $dateTimeFormatter; + /** @var MemoryInfo */ + private $memoryInfo; public function __construct($AppName, IRequest $request, @@ -94,7 +97,8 @@ class CheckSetupController extends Controller { EventDispatcherInterface $dispatcher, IDBConnection $db, ILockingProvider $lockingProvider, - IDateTimeFormatter $dateTimeFormatter) { + IDateTimeFormatter $dateTimeFormatter, + MemoryInfo $memoryInfo) { parent::__construct($AppName, $request); $this->config = $config; $this->clientService = $clientService; @@ -107,6 +111,7 @@ class CheckSetupController extends Controller { $this->db = $db; $this->lockingProvider = $lockingProvider; $this->dateTimeFormatter = $dateTimeFormatter; + $this->memoryInfo = $memoryInfo; } /** @@ -529,6 +534,16 @@ Raw output return function_exists('opcache_get_status'); } + /** + * Tests if the php memory limit is high enough. + * + * @return bool True if more than 512 MB available, else false. + */ + protected function isTheMemoryLimitHighEnough(): bool { + $memoryLimit = $this->memoryInfo->getMemoryLimit(); + return $memoryLimit === -1 || $memoryLimit >= 512 * 1024 * 1024; + } + /** * @return DataResponse */ @@ -565,7 +580,8 @@ Raw output 'isSqliteUsed' => $this->isSqliteUsed(), 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'), 'isPhpMailerUsed' => $this->isPhpMailerUsed(), - 'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin') + 'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'), + 'isTheMemoryLimitHighEnough' => $this->isTheMemoryLimitHighEnough(), ] ); }