Skip to content

Instantly share code, notes, and snippets.

@thonixx
Created August 25, 2013 15:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save thonixx/6334619 to your computer and use it in GitHub Desktop.
Save thonixx/6334619 to your computer and use it in GitHub Desktop.
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