memory_get_usage
Returns the amount of memory the program uses.
Syntax
memory_get_usage(bool $real_usage = false): intParameters
| Parameter | Type | Description |
|---|---|---|
| $real_usage | bool | Optional. `true` returns the memory allocated by the system. |
Return value
intThe number of bytes.
Examples
How much memory an array takes:
<?php
$before = memory_get_usage();
$numbers = range(1, 100000);
echo round((memory_get_usage() - $before) / 1024 / 1024, 1), ' MB';Notes
memory_get_peak_usage() returns the highest value during the run. The memory_limit setting defines the cap.
See also
Related recipes
In the tutorial
- Generators — Generators in PHP — the yield keyword, saving memory, keys, infinite sequences and reading large files.