Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test PHPs memory limit
<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
You can’t perform that action at this time.