Wrapper for retrieving information about PHP's memory with native PHP functions
Installation
$ composer require operating-system/php-memoryUsage
use OperatingSystem\Php\Memory\Memory as PhpMemory;
use Unit\Information\Unit;
$phpMemory = new PhpMemory();
$oldPhpMemoryLimit = ini_get('memory_limit');
ini_set('memory_limit', '128M');
// Get the configured PHP memory limit
$phpMemory->getConfiguredLimit()->format(Unit::MEBIBYTE); // '128MiB'
$phpMemory->getConfiguredLimit()->format(Unit::MEGABYTE); // '134.2MB'
// Get memory allocated by PHP
$phpMemory->getAllocated()->format();
$phpMemory->getAllocatedPeak()->format();
// Get memory used by PHP
$phpMemory->getUsed()->format();
$phpMemory->getUsedPeak()->format();
// Get the difference between configured limit and used memory
$phpMemory->getAvailable()->format();
// Get the difference between allocated memory and used memory
$phpMemory->getUnusedButAllocated()->format();
ini_set('memory_limit', $oldPhpMemoryLimit);For formatting details see https://packagist.org/packages/unit/information.
Testing
$ ./vendor/bin/phpunitLicense
The MIT License (MIT). Please see License File for more information.