Skip to content

Instantly share code, notes, and snippets.

@vijinho
Last active January 6, 2025 13:00
Show Gist options
  • Save vijinho/572b368d83efe33acae4 to your computer and use it in GitHub Desktop.
Save vijinho/572b368d83efe33acae4 to your computer and use it in GitHub Desktop.
get memory used in php
<?php
/**
* Get memory usage in megabytes.
*
* @return string Memory usage in the format "used/peak" where both values are in MB.
*/
function get_memory_used(): string {
$memoryUsage = memory_get_usage() / 1024 / 1024;
$peakMemoryUsage = memory_get_peak_usage() / 1024 / 1024;
return round($memoryUsage, 2) . '/' . round($peakMemoryUsage, 2);
}
// Example usage
echo get_memory_used();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment