summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-08-04 20:39:39 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-20 15:24:10 +0200
commitc2fced446396dad822404f3fae3ccb1c7df0dc89 (patch)
tree0d6daa452cd69b27ae534adcd92499747cde7e00 /lib/private
parent080572993e891a76721f4f7a7b76c85bc0e4c65d (diff)
downloadnextcloud-server-c2fced446396dad822404f3fae3ccb1c7df0dc89.tar.gz
nextcloud-server-c2fced446396dad822404f3fae3ccb1c7df0dc89.zip
Adds a setup check for the memory limit
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/MemoryInfo.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/private/MemoryInfo.php b/lib/private/MemoryInfo.php
new file mode 100644
index 00000000000..14865ed682e
--- /dev/null
+++ b/lib/private/MemoryInfo.php
@@ -0,0 +1,47 @@
+<?php
+
+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;
+ }
+}