composer require samlitowitz/php-memory
use PhpMemory\MemoryLimit;
use PhpMemory\Unit\Binary\Megabyte;
MemoryLimit::set(Size::create(2, new Megabyte()), true);
echo init_get(MemoryLimit::INI_OPTION);
// 1M
use PhpMemory\MemoryLimit;
use PhpMemory\Unit\Byte;
MemoryLimit::set(Size::create(100, new Byte()));
echo init_get(MemoryLimit::INI_OPTION);
// 100
See MemoryLimitTest for more examples.