Last active
October 6, 2021 21:00
-
-
Save philwinkle/5979436 to your computer and use it in GitHub Desktop.
Waste fixed amount of memory in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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