Created
November 14, 2014 18:31
-
-
Save attozk/a63b9d115aa84c2fd1fd to your computer and use it in GitHub Desktop.
understanding php memory GC with diff var name
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
// comparing against https://gist.github.com/attozk/5727bad9e621dbca4615 | |
<?php | |
$loader = include __DIR__ . '/../vendor/autoload.php'; | |
$loop = React\EventLoop\Factory::create(); | |
$counter = 0; | |
$timer = $loop->addPeriodicTimer(10, function() use(&$timer, &$counter) { | |
$counter++; | |
if ($counter > 1 && $counter <= 5) { | |
$queue = []; | |
$queue[$counter] = []; | |
for ($i = 0; $i < 100000; $i++) { | |
$queue[$counter] = rand(1,9999); | |
} | |
unset($queue); | |
} | |
echo | |
'Counter: ' . $counter . "\n" . | |
'Memory: ' . round(memory_get_usage() / 1024 / 1024, 2) . " MB\n" . | |
'Memory True: ' . round(memory_get_usage(true) / 1024 / 1024, 2) . " MB\n" . | |
'Peak Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 2) . "MB \n" . | |
'Peak Memory True : ' . round(memory_get_peak_usage(true) / 1024 / 1024, 2) . "MB \n" . "\n\n"; | |
if ($counter > 10) | |
die; | |
}); | |
$loop->run(); | |
/** outputs **/ | |
Counter: 10 | |
Memory: 0.29 MB | |
Memory True: 0.5 MB | |
Peak Memory: 0.38MB | |
Peak Memory True : 0.5MB | |
Counter: 11 | |
Memory: 0.29 MB | |
Memory True: 0.5 MB | |
Peak Memory: 0.38MB | |
Peak Memory True : 0.5MB | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment