Category
stdlib
Problem
memory_reset_peak_usage() is registered (#5539) and accepts zero arguments, but memory_get_peak_usage() does not drop after a large allocation is freed — unlike Zend. Issue #5108 still describes the function as missing; the remaining gap is behavioral parity of the peak counter reset.
Root cause: ext/standard/VmMemory.php tracks peak via RSS approximation (readRssBytes()). Freeing PHP variables does not shrink RSS, so resetPeakUsage() baselines peak at the still-high current RSS and get_peak_usage() reports reset_fail.
php-src reference
Repro (failure today)
<?php
$before = memory_get_peak_usage();
$str = str_repeat('x', 1 << 20);
$peak = memory_get_peak_usage();
unset($str);
memory_reset_peak_usage();
$after = memory_get_peak_usage();
echo ($peak > $before ? "peak_grew\n" : "peak_flat\n");
echo ($after < $peak ? "reset_ok\n" : "reset_fail\n");
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php repro.php
php repro.php # Zend in same container
'
Observed (VM, 2026-06-07): peak_grew + reset_fail.
Observed (Zend PHP 8.2 in container): peak_grew + reset_ok.
Also missing: bool $real_usage = false parameter and return value (tracked separately in #7247 MemoryUsage enum work).
Scope (PHP-in-PHP)
| Path |
Work |
ext/standard/VmMemory.php |
Track emalloc-style peak counters independently of RSS |
ext/standard/JitMemory.php / lib/JIT/Builtin/MemoryRuntime.php |
Mirror reset semantics in JIT/AOT |
| Tests |
extend test/compliance/cases/stdlib/memory_reset_peak_usage.phpt |
Implementation hints
php-src-strict
Default CI/compliance must match Zend peak reset after unset(); no php-compiler-strict shortcut unless static proof shows no user-visible peak introspection.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter memory_reset_peak_usage'
Pairs
Category
stdlibProblem
memory_reset_peak_usage()is registered (#5539) and accepts zero arguments, butmemory_get_peak_usage()does not drop after a large allocation is freed — unlike Zend. Issue #5108 still describes the function as missing; the remaining gap is behavioral parity of the peak counter reset.Root cause:
ext/standard/VmMemory.phptracks peak via RSS approximation (readRssBytes()). Freeing PHP variables does not shrink RSS, soresetPeakUsage()baselines peak at the still-high current RSS andget_peak_usage()reportsreset_fail.php-src reference
ext/standard/basic_functions.c—PHP_FUNCTION(memory_reset_peak_usage)Zend/zend_alloc.c—zend_reset_peak_memory_usage()Repro (failure today)
Observed (VM, 2026-06-07):
peak_grew+reset_fail.Observed (Zend PHP 8.2 in container):
peak_grew+reset_ok.Also missing:
bool $real_usage = falseparameter and return value (tracked separately in #7247 MemoryUsage enum work).Scope (PHP-in-PHP)
ext/standard/VmMemory.phpext/standard/JitMemory.php/lib/JIT/Builtin/MemoryRuntime.phptest/compliance/cases/stdlib/memory_reset_peak_usage.phptImplementation hints
memory_reset_peak_usage()should returnboolper Zend when Stdlib: MemoryUsage enum — PHP 8.4 memory_get_usage()/memory_get_peak_usage() real_usage parameter missing (ext/standard/basic_functions.stub.php) #7247 lands; this issue focuses on counter semantics.php-src-strict
Default CI/compliance must match Zend peak reset after
unset(); nophp-compiler-strictshortcut unless static proof shows no user-visible peak introspection.Done when
peak_grewthenreset_okon VM (matches Zend container run)memory_get_peak_usage()after reset ≤ baseline taken immediately after reset call$real_usage=truebranch (Stdlib: MemoryUsage enum — PHP 8.4 memory_get_usage()/memory_get_peak_usage() real_usage parameter missing (ext/standard/basic_functions.stub.php) #7247)./script/ci-fast.sh --filter memory_reset_peak_usagegreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter memory_reset_peak_usage'Pairs
$real_usage/ MemoryUsage enum)