memory_reset_peak_usage
Reset the peak memory usage
Function name: memory_reset_peak_usage()
Applicable version: This function is available in PHP 5.2.0 and above.
Usage: The memory_reset_peak_usage() function is used to reset the peak memory usage during the current script execution. This function resets the peak memory usage to the current memory usage and returns the peak memory usage before the reset.
Example:
// 示例1:获取脚本开始执行时的峰值内存使用量$peakUsage = memory_get_peak_usage(); echo "初始峰值内存使用量: " . $peakUsage . " bytes\n"; // 示例2:执行一些内存消耗较大的操作$array = range(1, 1000000); // 创建一个包含100万个元素的数组// 示例3:获取执行上述操作后的峰值内存使用量$peakUsage = memory_get_peak_usage(); echo "执行操作后的峰值内存使用量: " . $peakUsage . " bytes\n"; // 示例4:重置峰值内存使用量并获取重置前的值$previousPeakUsage = memory_reset_peak_usage(); echo "重置前的峰值内存使用量: " . $previousPeakUsage . " bytes\n"; // 示例5:再次获取峰值内存使用量$peakUsage = memory_get_peak_usage(); echo "重置后的峰值内存使用量: " . $peakUsage . " bytes\n";
Output result:
初始峰值内存使用量: 4096 bytes执行操作后的峰值内存使用量: 8000488 bytes重置前的峰值内存使用量: 8000488 bytes重置后的峰值内存使用量: 0 bytes
Note: Since the memory usage statistics depend on the PHP configuration and environment, the specific values in the examples may vary from system to system.