Last active
August 29, 2015 14:26
-
-
Save firebus/2e324b1261f0e2cbe1f9 to your computer and use it in GitHub Desktop.
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
class MemoryMash { | |
public function mash() { | |
str_pad('', $this->getMaxMemory()); | |
} | |
private function getMaxMemory() { | |
$memoryLimit = ini_get('memory_limit'); | |
if ($memoryLimit != -1) { | |
$memoryLimit = $this->return_bytes($memoryLimit); | |
} else { | |
# linuxy only, meh | |
exec('vmstat -s', $vmstat); | |
preg_match('/(\d+) (\w)/', $vmstat[0], $matches); | |
$memoryLimit = $this->return_bytes($matches[1] . $matches[2]); | |
} | |
return $memoryLimit; | |
} | |
#http://php.net/manual/en/function.ini-get.php#refsect1-function.ini-get-examples | |
private function return_bytes($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; | |
case 'm': | |
$val *= 1024; | |
case 'k': | |
$val *= 1024; | |
} | |
return $val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exhaust memory_limit (or actual memory on the server, maybe?)