Last active
January 3, 2016 12:29
-
-
Save syphoxy/8463247 to your computer and use it in GitHub Desktop.
Refactoring Magento code by example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function _getMemoryLimit() | |
{ | |
$memoryLimit = trim(strtoupper(ini_get('memory_limit'))); | |
if (!isSet($memoryLimit[0])){ | |
$memoryLimit = "128M"; | |
} | |
if (substr($memoryLimit, -1) == 'K') { | |
return substr($memoryLimit, 0, -1) * 1024; | |
} | |
if (substr($memoryLimit, -1) == 'M') { | |
return substr($memoryLimit, 0, -1) * 1024 * 1024; | |
} | |
if (substr($memoryLimit, -1) == 'G') { | |
return substr($memoryLimit, 0, -1) * 1024 * 1024 * 1024; | |
} | |
return $memoryLimit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const DEFAULT_MEMORY_LIMIT = 134217728; | |
protected function _getMemoryLimit() | |
{ | |
$memoryLimit = trim(ini_get('memory_limit')); | |
if (empty($memoryLimit)) { | |
return self::DEFAULT_MEMORY_LIMIT; | |
} | |
$multiple = stripos("KMGTPEZY", substr($memoryLimit, -1)); | |
if ($multiple !== false) { | |
return intval(substr($memoryLimit, 0, -1)) * pow(1024, $multiple + 1); | |
} | |
return $memoryLimit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment