> 有些大数据的处理,可能比较占用内存,为了找出内存溢出的原因,就需要用到`内存调试`:memory_get_usage() ~~~ $star_memory = memory_get_usage(); echo '开始内存:' . ($star_memory / 1024 / 1024) . 'M<br/>'; $tmp = str_repeat('hello', 1000); $array = []; for ($i = 0; $i < 830000; $i++) { $array[] = $i; } $aaa = ''; foreach ($array as $k => $v) { $aaa++; } $end_memory = memory_get_usage(); echo '运行后内存:' . ($end_memory / 1024 / 1024) . 'M<br/>'; echo '差值:' . (($end_memory - $star_memory) / 1024 / 1024).'M<br/>'; unset($tmp); unset($array); $final_memory = memory_get_usage(); echo '释放过后的内存:' . ($final_memory / 1024 / 1024) . 'M'; ~~~ > 开始内存:0.510009765625M > 运行后内存:32.52180480957M > 差值:32.011795043945M > 释放过后的内存:0.510009765625M