| Total Complexity | 6 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class Memory |
||
| 15 | { |
||
| 16 | public function __construct() |
||
| 17 | { |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * $real=true shows allocated memory (-> system monitoring) |
||
| 22 | * $real=null|false shows memory used by script (-> memory leak search) |
||
| 23 | * Do not take PHP external resources into account (remote/DB connection, SimpleXML, etc) |
||
| 24 | * See http://drib.tech/programming/get-real-amount-memory-allocated-php. |
||
| 25 | * |
||
| 26 | * @param bool|null $real |
||
| 27 | */ |
||
| 28 | public function echoMemory(?bool $real = null): void |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function memoryUsage(?bool $real = null): string |
||
| 39 | { |
||
| 40 | $memUsage = memory_get_usage($real); |
||
| 41 | |||
| 42 | return sprintf('usage: %s', $this->convert($memUsage)); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function memoryPeak(?bool $real = null): string |
||
| 50 | } |
||
| 51 | |||
| 52 | private function convert(int $size): string |
||
| 57 | } |
||
| 58 | } |
||
| 59 |