Skip to content

Instantly share code, notes, and snippets.

@philwinkle
Last active October 6, 2021 21:00
Show Gist options
  • Save philwinkle/5979436 to your computer and use it in GitHub Desktop.
Save philwinkle/5979436 to your computer and use it in GitHub Desktop.
Waste fixed amount of memory in PHP
<?php
/**
* Yeah yeah yeah, as if we need this, right?
* @author Phillip Jackson <[email protected]>
* @twitter philwinkle
*/
function waste($size){
$initSize = memory_get_usage();
while( (memory_get_usage()-$initSize) < $size){
//Prevent gc from running by assigning to GLOBALS
//Courtesy of @foomanNZ
$GLOBALS['waste'][] = 1;
}
}
waste(10485760); //10MB in bytes
waste(134217728); //128MB in bytes, default PHP CLI limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment