operating-system / php-memory
Wrapper for retrieving information about PHP's memory usage with native PHP functions
v1.0.2
2020-09-06 09:46 UTC
Requires
- php: ^7.4
- unit/information: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2021-02-06 10:51:07 UTC
README
Wrapper for retrieving information about PHP's memory with native PHP functions
Installation
$ composer require operating-system/php-memory
Usage
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/phpunit
License
The MIT License (MIT). Please see License File for more information.