summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-08-21 09:51:33 +0200
committerGitHub <noreply@github.com>2018-08-21 09:51:33 +0200
commit383699398fc48b50b76f4eebcb25a489bcd2ec58 (patch)
treec1c3d1c59f355ae327747693bb376da078ca1d8a /lib
parentbac545e7540295c39f94490536d0986a0693c533 (diff)
parent20839a422bd5fc33d6df1e778daae4999b181460 (diff)
downloadnextcloud-server-383699398fc48b50b76f4eebcb25a489bcd2ec58.tar.gz
nextcloud-server-383699398fc48b50b76f4eebcb25a489bcd2ec58.zip
Merge pull request #10539 from nextcloud/feature-8642-memory-check
Adds a setup and cli check for the recommended memory limit
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Console/Application.php19
-rw-r--r--lib/private/MemoryInfo.php81
4 files changed, 101 insertions, 1 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 5b60dbd871f..f411a288f22 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -830,6 +830,7 @@ return array(
'OC\\Memcache\\Memcached' => $baseDir . '/lib/private/Memcache/Memcached.php',
'OC\\Memcache\\NullCache' => $baseDir . '/lib/private/Memcache/NullCache.php',
'OC\\Memcache\\Redis' => $baseDir . '/lib/private/Memcache/Redis.php',
+ 'OC\\MemoryInfo' => $baseDir . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => $baseDir . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => $baseDir . '/lib/private/Migration/ConsoleOutput.php',
'OC\\Migration\\SimpleOutput' => $baseDir . '/lib/private/Migration/SimpleOutput.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index d91c4833b75..35ce1ed09ff 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -860,6 +860,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Memcache\\Memcached' => __DIR__ . '/../../..' . '/lib/private/Memcache/Memcached.php',
'OC\\Memcache\\NullCache' => __DIR__ . '/../../..' . '/lib/private/Memcache/NullCache.php',
'OC\\Memcache\\Redis' => __DIR__ . '/../../..' . '/lib/private/Memcache/Redis.php',
+ 'OC\\MemoryInfo' => __DIR__ . '/../../..' . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => __DIR__ . '/../../..' . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/ConsoleOutput.php',
'OC\\Migration\\SimpleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/SimpleOutput.php',
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php
index 1de5fbd6ca3..0e30fa02b94 100644
--- a/lib/private/Console/Application.php
+++ b/lib/private/Console/Application.php
@@ -29,6 +29,7 @@
*/
namespace OC\Console;
+use OC\MemoryInfo;
use OC\NeedsUpdateException;
use OC_App;
use OCP\AppFramework\QueryException;
@@ -52,20 +53,28 @@ class Application {
private $request;
/** @var ILogger */
private $logger;
+ /** @var MemoryInfo */
+ private $memoryInfo;
/**
* @param IConfig $config
* @param EventDispatcherInterface $dispatcher
* @param IRequest $request
* @param ILogger $logger
+ * @param MemoryInfo $memoryInfo
*/
- public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) {
+ public function __construct(IConfig $config,
+ EventDispatcherInterface $dispatcher,
+ IRequest $request,
+ ILogger $logger,
+ MemoryInfo $memoryInfo) {
$defaults = \OC::$server->getThemingDefaults();
$this->config = $config;
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
$this->dispatcher = $dispatcher;
$this->request = $request;
$this->logger = $logger;
+ $this->memoryInfo = $memoryInfo;
}
/**
@@ -97,6 +106,14 @@ class Application {
if ($input->getOption('no-warnings')) {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
+
+ if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
+ $output->getErrorOutput()->writeln(
+ '<comment>The current PHP memory limit ' .
+ 'is below the recommended value of 512MB.</comment>'
+ );
+ }
+
try {
require_once __DIR__ . '/../../../core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
diff --git a/lib/private/MemoryInfo.php b/lib/private/MemoryInfo.php
new file mode 100644
index 00000000000..4b8d2bce37b
--- /dev/null
+++ b/lib/private/MemoryInfo.php
@@ -0,0 +1,81 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2018, Michael Weimann (<mail@michael-weimann.eu>)
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC;
+
+/**
+ * Helper class that covers memory info.
+ */
+class MemoryInfo {
+
+ const RECOMMENDED_MEMORY_LIMIT = 512 * 1024 * 1024;
+
+ /**
+ * Tests if the memory limit is greater or equal the recommended value.
+ *
+ * @return bool
+ */
+ public function isMemoryLimitSufficient(): bool {
+ $memoryLimit = $this->getMemoryLimit();
+ return $memoryLimit === -1 || $memoryLimit >= self::RECOMMENDED_MEMORY_LIMIT;
+ }
+
+ /**
+ * Returns the php memory limit.
+ *
+ * @return int The memory limit in bytes.
+ */
+ public function getMemoryLimit(): int {
+ $iniValue = trim(ini_get('memory_limit'));
+ if ($iniValue === '-1') {
+ return -1;
+ } else if (is_numeric($iniValue) === true) {
+ return (int)$iniValue;
+ } else {
+ return $this->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;
+ }
+}