Skip to content

Instantly share code, notes, and snippets.

@philwinkle
Last active October 6, 2021 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 <philwinkle@gmail.com>
* @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