Last active
January 6, 2025 13:00
-
-
Save vijinho/572b368d83efe33acae4 to your computer and use it in GitHub Desktop.
get memory used in php
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
<?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