Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test PHPs memory limit
$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";
$limit = $i.'M';
ini_set('memory_limit', $limit);
echo "set memory_limit to {$limit}\n";
echo "memory limit is ". ini_get("memory_limit")."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment