- memory_get_peak_usage: documentation ( source)
- memory_get_usage: documentation ( source)
- implode: documentation ( source)
- range: documentation ( source)
- str_pad: documentation ( source)
<?php
$buf = '';
report_memory(__LINE__);
$buf = implode(range(1,PHP_MAX_INT));
report_memory(__LINE__);
example($buf);
report_memory(__LINE__);
example2($buf);
report_memory(__LINE__);
function example($str) {
report_memory(__LINE__);
is_string($str);
report_memory(__LINE__);
}
function example2(& $str) {
report_memory(__LINE__);
is_string($str);
report_memory(__LINE__);
}
function report_memory($line=0) {
echo 'Line: ' . str_pad($line,3) . ' ';
echo 'Mem: ' . str_pad(intval(memory_get_usage()/1024 ) . 'K',8) . ' ';
echo 'Peak: ' . str_pad(intval(memory_get_peak_usage()/1024) . 'K',8) . ' ';
echo "\n";
}