|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-06-03 23:43 UTC] tandre@php.net
[2021-06-04 08:24 UTC] pvandommelen at gmail dot com
[2021-06-04 11:40 UTC] cmb@php.net
[2021-06-04 13:06 UTC] nikic@php.net
[2021-06-04 13:25 UTC] pvandommelen at gmail dot com
[2021-06-08 12:34 UTC] git@php.net
[2021-06-08 12:34 UTC] git@php.net
-Status: Open
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Description: ------------ This only happens when PHP is built with `--enable-debug`, and it's only a notice. Possibly, it's deliberate. `php -d memory_limit=5M test.php` on the attached script will run the script successfully, and while php is shutting down, php will internally reset original ini settings, including memory_limit. This will trigger an error because the restored memory_limit is smaller than the amount of memory recorded as being in use at the time - this is more likely to affect programs with data structures that can't be garbage collected (gc_disable(); public function __construct() { $this->x = [$this]; }) ``` (gdb) b zend_error Breakpoint 1 at 0x613f69: file /path/to/php-src/Zend/zend.c, line 1561. (gdb) run Starting program: /path/to/php-8.1.0-debug-intersection-types-install/bin/php -d memory_limit=5M test.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Memory usage before shutting down: 11975904 Breakpoint 1, zend_error (type=21845, format=0x555556379140 "\001") at /path/to/php-src/Zend/zend.c:1561 1561 ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) { (gdb) bt #0 zend_error (type=21845, format=0x555556379140 "\001") at /path/to/php-src/Zend/zend.c:1561 #1 0x0000555555ac1824 in OnChangeMemoryLimit (entry=0x55555637ebe0, new_value=0x55555637ec60, mh_arg1=0x0, mh_arg2=0x0, mh_arg3=0x0, stage=8) at /path/to/php-src/main/main.c:276 #2 0x0000555555c1d8eb in zend_restore_ini_entry_cb (ini_entry=0x55555637ebe0, stage=8) at /path/to/php-src/Zend/zend_ini.c:54 #3 0x0000555555c1db8c in zend_ini_deactivate () at /path/to/php-src/Zend/zend_ini.c:129 #4 0x0000555555b672ac in zend_deactivate () at /path/to/php-src/Zend/zend.c:1290 #5 0x0000555555ac4d17 in php_request_shutdown (dummy=0x0) at /path/to/php-src/main/main.c:1823 #6 0x0000555555cd21d2 in do_cli (argc=4, argv=0x555556378cb0) at /path/to/php-src/sapi/cli/php_cli.c:1134 #7 0x0000555555cd2ab6 in main (argc=4, argv=0x555556378cb0) at /path/to/php-src/sapi/cli/php_cli.c:1366 ``` Perhaps the memory_limit should be a special case, and only be restored after everything else shuts down, and memory is freed? This is emitted as a notice to stdout when running https://github.com/phan/phan to self-analyze itself in php 8.1 with the default memory limit of 138 MB (phan generates cyclic data structures in some places, such as union type representations) Test script: --------------- <?php // Run this with `php -d memory_limit=5M test.php` class X { public $x; public function __construct() { $this->x = [$this]; } } gc_disable(); ini_set('memory_limit', '1G'); $y = []; for ($i = 0; $i < 20000; $i++) { $y[] = new X(); } $y[0]->y = &$y; $y[0]->z = $x; echo "Memory usage before shutting down: " . memory_get_usage() . "\n"; // Observed in php 8.1: // Warning: Failed to set memory limit to 5242880 bytes (Current memory usage is 12582912 bytes) in Unknown on line 0 Expected result: ---------------- No warning should be emitted during shutdown for a request Actual result: -------------- `Warning: Failed to set memory limit to 5242880 bytes (Current memory usage is 12582912 bytes) in Unknown on line 0` is emitted when php automatically tries to restore the system memory limit (`php -d memory_limit=5M`)