Memory Limiter is a PHP library that contains functionality to read the currently available/free memory of the system and to set the PHP memory limit according to the available memory.
Supports the following environments:
- Bare Metal Linux
- VM Linux
- Kubernetes Linux container
- Linux container (Docker, Podman, etc.)
composer require orlandothoeny/memory-limiter
<?php
use MemoryLimiter\AvailableMemoryReader;
$availableMemoryReader = AvailableMemoryReader::create();
$availableMemory = $availableMemoryReader->determineAvailableMemoryBytes();
<?php
use MemoryLimiter\MemoryLimiter;
$memoryLimiter = MemoryLimiter::create();
/* Set memory limit to the currently available memory
Will skip setting the memory limit if running inside a Kubernetes container */
$memoryLimiter->setMemoryLimitToCurrentlyAvailableMemory();
// Also set memory limit when running inside a Kubernetes container
$memoryLimiter->setMemoryLimitToCurrentlyAvailableMemory(false);
// Set memory limit to 50% of the currently available memory
$memoryLimiter->setMemoryLimitToCurrentlyAvailableMemory(
limitToPercentageOfAvailableMemory: 50
);
- Teleboy: Sponsored initial development
See the releases page for a list of all releases. Releases are documented in the CHANGELOG.
This project uses semantic versioning as its versioning scheme.
rm -f .git/hooks/pre-commit
cp dev-environment/pre-commit.sh .git/hooks/pre-commit
Prerequisites:
make quickstart
docker compose build
docker compose up -d
Available commands:
- php
- composer
docker compose exec php sh
docker compose down
docker compose exec php composer test
docker compose exec php composer phpstan
docker compose exec php composer cs-fix