Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adds a setup check for the memory limit
Signed-off-by: Michael Weimann <[email protected]>
  • Loading branch information
weeman1337 authored and skjnldsv committed Aug 20, 2018
commit c2fced446396dad822404f3fae3ccb1c7df0dc89
9 changes: 9 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
47 changes: 47 additions & 0 deletions lib/private/MemoryInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare strict types, please, and also the license header as found on other PHP files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I added the license texts and PHP strict mode.


namespace OC;

/**
* Helper class that covers memory info.
*/
class MemoryInfo {
/**
* 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;
}
}
20 changes: 18 additions & 2 deletions settings/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -81,6 +82,8 @@ class CheckSetupController extends Controller {
private $lockingProvider;
/** @var IDateTimeFormatter */
private $dateTimeFormatter;
/** @var MemoryInfo */
private $memoryInfo;

public function __construct($AppName,
IRequest $request,
Expand All @@ -94,7 +97,8 @@ public function __construct($AppName,
EventDispatcherInterface $dispatcher,
IDBConnection $db,
ILockingProvider $lockingProvider,
IDateTimeFormatter $dateTimeFormatter) {
IDateTimeFormatter $dateTimeFormatter,
MemoryInfo $memoryInfo) {
parent::__construct($AppName, $request);
$this->config = $config;
$this->clientService = $clientService;
Expand All @@ -107,6 +111,7 @@ public function __construct($AppName,
$this->db = $db;
$this->lockingProvider = $lockingProvider;
$this->dateTimeFormatter = $dateTimeFormatter;
$this->memoryInfo = $memoryInfo;
}

/**
Expand Down Expand Up @@ -529,6 +534,16 @@ protected function hasOpcacheLoaded(): bool {
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
*/
Expand Down Expand Up @@ -565,7 +580,8 @@ public function check() {
'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(),
]
);
}
Expand Down