Last active
September 11, 2015 01:14
-
-
Save jesseschalken/522d6e6c8a3f7fd4d010 to your computer and use it in GitHub Desktop.
Class to increase/decrease PHP's memory_limit by a given amount
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 | |
class MemoryLimit { | |
private $num = 0; | |
function inc($num) { | |
if (!$num) | |
return; | |
$this->num += $num; | |
$val = trim(ini_get('memory_limit')); | |
switch (strtolower($val[strlen($val)-1])) { | |
case 'g': | |
$val *= 1024; | |
case 'm': | |
$val *= 1024; | |
case 'k': | |
$val *= 1024; | |
} | |
if ($val != -1) { | |
$val += $num; | |
ini_set('memory_limit', $val); | |
} | |
} | |
function __destruct() { | |
$this->inc(-$this->num); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment