通过侦测脚本的内存使用情况,有利于代码的优化。PHP 提供了一个垃圾收集器和一个非常复杂的内存管理器。脚本执行时所使用的内存量,有升有跌。为了得到当前的内存使用情况,我们可以使用 memory_get_usage() 函数。如果需要获得任意时间点的最高内存使用量,则可以使用 memory_limit() 函数。view sourceprint?01 echo "Initial:
代码如下 | 复制代码 |
".memory_get_usage()." bytes "; 02 /* prints 03 Initial: 361400 bytes 04 */ 05 06 // let's use up some memory 07 for ($i = 0; $i 08 $array []= md5($i); 09 } 10 11 // let's remove half of the array 12 for ($i = 0; $i 13 unset($array[$i]); 14 } 15 16 echo "Final: ".memory_get_usage()." bytes "; 17 /* prints 18 Final: 885912 bytes 19 */ 20 21 echo "Peak: ".memory_get_peak_usage()." bytes "; 22 /* prints 23 Peak: 13687072 bytes |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)