commit 95aca7a71e26d7e870cd5733a55d7de4ffba6a07
parent b977bbcecf82087ea80bc8698d8099f9f8709ee8
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 8 Oct 2015 17:29:49 +0200
Check minimum required memory_limit
Diffstat:
1 file changed, 54 insertions(+), 6 deletions(-)
diff --git a/app/PartKeeprRequirements.php b/app/PartKeeprRequirements.php
@@ -19,23 +19,71 @@ class PartKeeprRequirements extends SymfonyRequirements
sprintf('GD library not found'),
sprintf('Install the GD library extension'));
+
+ $this->addPhpIniRequirement("memory_limit", $this->getBytesIniSetting("memory_limit") > 64000000,
+ false,
+ "Memory Limit too small",
+ sprintf("The php.ini memory_limit directive must be set to 64MB or higher. Your limit is set to %s",
+ ini_get("memory_limit")));
+
try {
- $this->is_writable_recursive(realpath(dirname(__FILE__). "/../data/"));
+ $this->isWritableRecursive(realpath(dirname(__FILE__)."/../data/"));
} catch (\Exception $e) {
$this->addRequirement(
- false,
- sprintf('Directory or file not writable'),
- $e->getMessage());
+ false,
+ sprintf('Directory or file not writable'),
+ $e->getMessage());
+ }
+
+ }
+
+ /**
+ * Returns a php.ini setting with parsed byte values.
+ *
+ * Example: If you specify memory_limit=64M, this method will return 67108864 bytes.
+ * @param $setting string The php.ini setting
+ *
+ * @return int The byts
+ */
+ protected function getBytesIniSetting($setting)
+ {
+ return (int)$this->returnBytes(ini_get($setting));
+ }
+
+ /**
+ * Parses a value with g,m or k modifiers and returns the effective bytes.
+ * @param $val string The value to parse
+ *
+ * @return int|string The bytes
+ */
+ protected function returnBytes($val)
+ {
+ $val = trim($val);
+ $last = strtolower($val[strlen($val) - 1]);
+ switch ($last) {
+ // The 'G' modifier is available since PHP 5.1.0
+ case 'g':
+ $val *= 1024;
+ break;
+ case 'm':
+ $val *= 1024;
+ break;
+ case 'k':
+ $val *= 1024;
+ break;
}
+ return $val;
}
/**
* Checks if the given directory and all contained files within it is writable by the current user.
*
* @param string $dir The directory to check
+ * @return boolean True if the path is writable
+ * @throws \Exception If the directory is not writable
*/
- public function is_writable_recursive($dir)
+ protected function isWritableRecursive($dir)
{
if (!is_writable($dir)) {
throw new \Exception($dir." is not writable.");
@@ -49,7 +97,7 @@ class PartKeeprRequirements extends SymfonyRequirements
throw new \Exception($dir."/".$file." is not writable.");
} else {
if (is_dir($dir."/".$file)) {
- if (!$this->is_writable_recursive($dir."/".$file)) {
+ if (!$this->isWritableRecursive($dir."/".$file)) {
closedir($folder);
throw new \Exception($dir."/".$file." is not writable.");
}