memory_get_peak_usage
Returns the peak memory allocated by PHP
Function name: memory_get_peak_usage()
Applicable version: PHP 5 >= 5.2.0, PHP 7
Usage: The memory_get_peak_usage() function is used to obtain the memory peak usage during the current script execution. It returns an integer representing the memory usage in bytes.
Example:
// 示例1:获取当前脚本的内存峰值使用量$peakUsage = memory_get_peak_usage(); echo "当前脚本的内存峰值使用量为:" . $peakUsage . " 字节"; // 示例2:获取某个函数或代码段的内存峰值使用量function myFunction() { $data = str_repeat("Hello", 1000000); // 生成一个较大的字符串echo "当前函数的内存峰值使用量为:" . memory_get_peak_usage() . " 字节"; } myFunction();
Notes: