Adds a memory limit warning for console commands if the limit is below the recommended value
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
This commit is contained in:
parent
1d2bc9c45e
commit
c164409ee7
|
@ -85,7 +85,13 @@ try {
|
||||||
echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
|
echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger());
|
$application = new Application(
|
||||||
|
\OC::$server->getConfig(),
|
||||||
|
\OC::$server->getEventDispatcher(),
|
||||||
|
\OC::$server->getRequest(),
|
||||||
|
\OC::$server->getLogger(),
|
||||||
|
\OC::$server->query(\OC\MemoryInfo::class)
|
||||||
|
);
|
||||||
$application->loadCommands(new ArgvInput(), new ConsoleOutput());
|
$application->loadCommands(new ArgvInput(), new ConsoleOutput());
|
||||||
$application->run();
|
$application->run();
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
|
|
@ -316,7 +316,7 @@
|
||||||
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
|
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!data.isTheMemoryLimitHighEnough) {
|
if (!data.isMemoryLimitSufficient) {
|
||||||
messages.push({
|
messages.push({
|
||||||
msg: t(
|
msg: t(
|
||||||
'core',
|
'core',
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Console;
|
namespace OC\Console;
|
||||||
|
|
||||||
|
use OC\MemoryInfo;
|
||||||
use OC\NeedsUpdateException;
|
use OC\NeedsUpdateException;
|
||||||
use OC_App;
|
use OC_App;
|
||||||
use OCP\AppFramework\QueryException;
|
use OCP\AppFramework\QueryException;
|
||||||
|
@ -52,20 +53,28 @@ class Application {
|
||||||
private $request;
|
private $request;
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
/** @var MemoryInfo */
|
||||||
|
private $memoryInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
* @param EventDispatcherInterface $dispatcher
|
* @param EventDispatcherInterface $dispatcher
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
* @param ILogger $logger
|
* @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();
|
$defaults = \OC::$server->getThemingDefaults();
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
|
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->memoryInfo = $memoryInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,6 +106,11 @@ class Application {
|
||||||
if ($input->getOption('no-warnings')) {
|
if ($input->getOption('no-warnings')) {
|
||||||
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
|
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
|
||||||
|
$this->writeMemoryLimitInfo($output);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
require_once __DIR__ . '/../../../core/register_command.php';
|
require_once __DIR__ . '/../../../core/register_command.php';
|
||||||
if ($this->config->getSystemValue('installed', false)) {
|
if ($this->config->getSystemValue('installed', false)) {
|
||||||
|
@ -173,6 +187,20 @@ class Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a memory info output if the limit is below the recommended value.
|
||||||
|
*
|
||||||
|
* @param ConsoleOutputInterface $output
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function writeMemoryLimitInfo(ConsoleOutputInterface $output) {
|
||||||
|
$errOutput = $output->getErrorOutput();
|
||||||
|
$errOutput->writeln(
|
||||||
|
'<comment>The current PHP memory limit ' .
|
||||||
|
'is below the recommended value of 512MB.</comment>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether to automatically exit after a command execution or not.
|
* Sets whether to automatically exit after a command execution or not.
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,6 +6,19 @@ namespace OC;
|
||||||
* Helper class that covers memory info.
|
* Helper class that covers memory info.
|
||||||
*/
|
*/
|
||||||
class MemoryInfo {
|
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.
|
* Returns the php memory limit.
|
||||||
*
|
*
|
||||||
|
|
|
@ -534,16 +534,6 @@ Raw output
|
||||||
return function_exists('opcache_get_status');
|
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
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
@ -581,7 +571,7 @@ Raw output
|
||||||
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
|
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
|
||||||
'isPhpMailerUsed' => $this->isPhpMailerUsed(),
|
'isPhpMailerUsed' => $this->isPhpMailerUsed(),
|
||||||
'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
|
'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
|
||||||
'isTheMemoryLimitHighEnough' => $this->isTheMemoryLimitHighEnough(),
|
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue