https://github.com/brandembassy/php-memory
A simple tool to provide an easy-to-use API to convert memory limit configuration from php.ini to bytes.
https://github.com/brandembassy/php-memory
memory memory-allocation php php7
Last synced: about 1 month ago
JSON representation
A simple tool to provide an easy-to-use API to convert memory limit configuration from php.ini to bytes.
- Host: GitHub
- URL: https://github.com/brandembassy/php-memory
- Owner: BrandEmbassy
- License: mit
- Created: 2018-04-21T14:09:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-20T03:44:49.000Z (4 months ago)
- Last Synced: 2025-04-20T17:19:54.947Z (2 months ago)
- Topics: memory, memory-allocation, php, php7
- Language: PHP
- Size: 33.2 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Memory Limit
A simple tool to provide an easy-to-use API to convert memory limit configuration from `php.ini` to bytes.
## Why
Core directive `memory_limit` in `php.ini` is a simple string. An administrator or a programmer can set several valid values, e.g.:
- `500` = 500 bytes
- `128M` = 134 217 728 bytes
- `1G` = 1 073 741 824 bytesYou can obtain the original string value through `ini_get('memory_limit')` function. However, there is no built-in PHP function to provide an easy access to the byte value.
## Installation
Add the package to your `composer.json`:```
composer require brandembassy/php-memory
```## Usage
Create the `MemoryLimitProvider `service (or better, inject it using your DI container):
```
$configuration = new \BrandEmbassy\Memory\MemoryConfiguration();
$limitProvider = new \BrandEmbassy\Memory\MemoryLimitProvider($configuration);
```There is also a DI extension for Nette Framework (you must have the `nette/di` package installed). Just register it in your `services.neon` file:
```
extensions:
- BrandEmbassy\Memory\Bridge\MemoryLimitNetteExtension
```You can then access the byte value of PHP memory limit like this:
```
$limitInBytes = $memoryLimitProvider->getLimitInBytes();
```*Any questions or ideas to improve? Feel free to open an issue or send a PR!*