operating-system/php-memory

Wrapper for retrieving information about PHP's memory usage with native PHP functions

v1.0.1 2018-12-20 09:31 UTC

This package is auto-updated.

Last update: 2020-01-20 12:02:56 UTC


README

Wrapper for retrieving information about PHP's memory with native PHP functions

Installation

composer require operating-system/php-memory

Usage

Instantiate memory:

use OperatingSystem\Php\Memory\Memory;

$memory = new Memory();

Get memory information:

$oldPhpMemoryLimit = \ini_get('memory_limit');
\ini_set('memory_limit', '128MB');

$phpMemory->getConfiguredLimit()->format();             // '128MB'
$phpMemory->getAllocated()->format();                   // '2.097152MB'
$phpMemory->getUsed()->format();                        // '624.48kB'
$phpMemory->getAvailable()->format();                   // '127.375008MB'
$phpMemory->getUnusedButAllocated()->format();          // '1.47212MB'
$phpMemory->getAllocatedPeak()->format();               // '2.097152MB'
$phpMemory->getUsedPeak()->format();                    // '752.696kB'

$phpMemory->getConfiguredLimit()->format('MB', 1);      // '128.0MB'
$phpMemory->getAllocated()->format('MB', 1);            // '2.1MB'
$phpMemory->getUsed()->format('MB', 1);                 // '0.6MB'
$phpMemory->getAvailable()->format('MB', 1);            // '127.4MB'
$phpMemory->getUnusedButAllocated()->format('MB', 1);   // '1.5MB'
$phpMemory->getAllocatedPeak()->format('MB', 1);        // '2.1MB'
$phpMemory->getUsedPeak()->format('MB', 1);             // '0.8MB'

\ini_set('memory_limit', $oldPhpMemoryLimit);

Testing

$ ./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.