Created
August 25, 2013 15:54
-
-
Save thonixx/6334619 to your computer and use it in GitHub Desktop.
Test PHPs 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
<pre> | |
<?php | |
$megabyte = 1528; // define the max megabytes which should be tested | |
function tryAlloc($megabyte){ | |
echo "try allocating {$megabyte} megabyte..."; | |
$mb = $megabyte; | |
$dummy = str_repeat("-",1048576*$mb); | |
echo "pass."; | |
echo "Usage: " . memory_get_usage(true)/1048576; | |
echo " Peak: " . memory_get_peak_usage(true)/1048576; | |
echo "\n"; | |
} | |
for($i=8;$i<=$megabyte;$i+=8){ | |
$limit = $i.'M'; | |
ini_set('memory_limit', $limit); | |
echo "set memory_limit to {$limit}\n"; | |
echo "memory limit is ". ini_get("memory_limit")."\n"; | |
tryAlloc($i-1); | |
} | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment