[php-src] Issue #21862: `memory_limit` is ignored

From: Date: Fri, 24 Apr 2026 10:28:01 +0000
Subject: [php-src] Issue #21862: `memory_limit` is ignored
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252008@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/21862 Author: mvorisek ### Description The following code: ```php <?php $logFx = function ($v, $clear = false) { $p = __DIR__ . '/../../log'; ob_start(); var_dump($v); $str = ob_get_clean(); file_put_contents($p, $str, $clear ? 0 : FILE_APPEND); }; $logFx('', true); $logFx(ini_get('memory_limit')); $logFx('x'); $logFx(memory_get_usage(true)); $logFx(memory_get_usage(false)); ini_set('memory_limit', '16M'); $str = ''; for ($i = 0; $i < 4 * 1024; ++$i) { $str .= random_bytes(16 * 1024); $logFx(memory_get_usage(true)); } $logFx(memory_get_usage(true)); $logFx(memory_get_usage(false)); $logFx(ini_get('memory_limit')); $logFx('y'); ``` repro repo: https://github.com/atk4/ui/tree/refs/heads/php_memory_limit_ignored Resulted in this output: ``` int(200) string(57473) "string(0) "" string(4) "128M" string(1) "x" int(18874368) int(1950048) ... int(83824640) int(83841024) int(83857408) int(83873792) int(83890176) int(83890176) int(69063032) string(3) "16M" string(1) "y" ``` But I expected this output instead: ``` int(200) string(57473) "string(0) "" string(4) "128M" string(1) "x" int(18874368) int(1950048) ... must terminate before this is output: string(1) "y" ``` PHP, randomly ignores memory_limit and it seems it allocates a new memory page even when real memory usage is already over the limit. ### PHP Version ```plain PHP 8.5.5 (cli) (built: Apr 22 2026 11:22:58) (NTS) Copyright (c) The PHP Group Built by https://github.com/docker-library/php Zend Engine v4.5.5, Copyright (c) Zend Technologies with Xdebug v3.5.1, Copyright (c) 2002-2026, by Derick Rethans with Zend OPcache v8.5.5, Copyright (c), by Zend Technologies ``` ### Operating System linux

« previous php.bugs (#252008) next »