Check memory used by a script

06 February 2019 — Written by Mitesh Patel
#php#performance#memory

Check memory used by a script.

<?php
// Add these lines at the end of your code.
echo PHP_EOL;
echo "Memory Usage :" . memory_get_usage();
echo PHP_EOL;
echo "Real Memory Usage :" . memory_get_usage(true);
echo PHP_EOL;
echo "Real Peak Memory Usage :" . memory_get_peak_usage(true);
echo PHP_EOL;
echo "Peak Memory Usage :" . memory_get_peak_usage();
echo PHP_EOL;
view raw memory-usage.php hosted with ❤ by GitHub

Copyright © 2021 Mitesh Patel. Built with Gatsby