Created
May 13, 2019 18:24
-
-
Save thbighead/b86e0170c192b78d34384fd9e0595fe9 to your computer and use it in GitHub Desktop.
Using return_bytes, this helper runs the Garbage Collector when the memory usage passes a given percentage
This file contains hidden or 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
/** | |
* @param float $percentage A value between 0 and 1 | |
*/ | |
function cleanMemoryWithGC($percentage) | |
{ | |
if ((return_bytes(ini_get('memory_limit')) * $percentage) <= memory_get_usage()) { | |
$percentage *= 100; | |
Log::info('cleanMemoryWithGC', ['message' => "Rodando o Garbage Collector, pois mais de $percentage% do limite de memória disponível para o PHP está sendo utilizado..."]); | |
gc_collect_cycles(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment