- var_dump: documentation ( source)
- memory_get_peak_usage: documentation ( source)
- gc_collect_cycles: documentation ( source)
- round: documentation ( source)
<?php
class Foo {
private $orig;
public function bar() {
$this->orig = clone $this;
}
}
$foo = new Foo;
$history = array();
$last = 0;
for ($i = 0; $i < 5000; $i++) {
$foo->bar();
gc_collect_cycles();
$peak = round(memory_get_peak_usage(true) / 1024 / 1024, 2);
if ($peak != $last) {
$history[] = $peak;
$last = $peak;
}
}
var_dump($history);