To get the total memory of the server in PHP, we can use the memory_get_peak_usage()
function. It returns the peak memory usage in bytes, from the start of the script execution.
To convert it to a more readable format, we can use the memory_format()
function which takes in the byte count and returns it in MB, GB or TB format, depending on the size.
main.php334 chars11 lines
Note: memory_get_peak_usage()
may not work in all environments, or may return inaccurate results due to various factors such as caching, or other processes running on the server.
gistlibby LogSnag