Created
April 1, 2014 03:05
-
-
Save daftspunk/9906962 to your computer and use it in GitHub Desktop.
PHP Increase memory limit (set_memory_limit)
This file contains hidden or 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 | |
| /** | |
| * Increase memory limit if not already | |
| * @param $limit Amount in megabytes | |
| */ | |
| private function increaseMemoryLimit($limit = 512) | |
| { | |
| $limitBytes = $limit * 1048576; | |
| $currentLimit = trim(ini_get('memory_limit')); | |
| $lastChar = strtolower($currentLimit[strlen($currentLimit)-1]); | |
| switch($lastChar) { | |
| case 'g': | |
| $currentLimit *= 1024; | |
| case 'm': | |
| $currentLimit *= 1024; | |
| case 'k': | |
| $currentLimit *= 1024; | |
| } | |
| if ($currentLimit < $limitBytes) | |
| ini_set('memory_limit', $limit . 'M'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment