PHP code example of bert-w / memory-usage

1. Go to this page and download the library: Download bert-w/memory-usage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bert-w / memory-usage example snippets


$memory = new \BertW\MemoryUsage\MemoryUsage();

$usage = $memory->usedMemory() . ' / ' . $memory->totalMemory();
// Result: "3486252 kB / 8148216 kB"


$usage = $memory->usedMemory()->to('GB') . ' / ' . $memory->totalMemory()->to('GB');
// Result: "3.32 GB / 7.77 GB"

(new \BertW\MemoryUsage\MemoryUsage)->usedMemory();
(new \BertW\MemoryUsage\MemoryUsage)->totalUsedMemory();
(new \BertW\MemoryUsage\MemoryUsage)->totalMemory();
(new \BertW\MemoryUsage\MemoryUsage)->cacheMemory();
(new \BertW\MemoryUsage\MemoryUsage)->nonCacheMemory();
(new \BertW\MemoryUsage\MemoryUsage)->swapMemory();
(new \BertW\MemoryUsage\MemoryUsage)->bufferMemory();

(new \BertW\MemoryUsage\MemoryUsage)->meminfo();
// Returns Array<string, int> with parsed `/proc/meminfo` content (in kilobytes).

(new \BertW\MemoryUsage\MemoryUsage)->get(\BertW\MemoryUsage\Meminfo::Buffers);
(new \BertW\MemoryUsage\MemoryUsage)->get('Buffers');
// Retrieve any value from the `/proc/meminfo` file. Accepts strings and Enums.