Git Product home page Git Product logo

memory-usage's Introduction

bert-w/memory-usage

Latest Stable Version Total Downloads License

Receive information about the current memory usage on your unix machine, similar to the calculations in htop.

Installation instructions

composer require bert-w/memory-usage

This package is only compatible with unix-like systems. It requires read permissions to the file /proc/meminfo which contains details about the memory usage on the system.

Quick start

Get the current memory usage of your system:

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

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

Results are in kB (kilobyte) format by default. They can be converted using the ->to() function which accepts a conversion unit like 'B', 'kB', 'MB', 'GB', 'TB', 'PB' or 'EB'. A handy __toString() is included which outputs the value and the unit name:

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

Function list

(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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.