Skip to content

Commit c99a54a

Browse files
committed
Make sure to modify memory_limit value through the registered handler.
1 parent 010fbd0 commit c99a54a

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

Zend/zend_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ EMPTY_SWITCH_DEFAULT_CASE()
636636
_(ZEND_STR_SINCE, "since") \
637637
_(ZEND_STR_GET, "get") \
638638
_(ZEND_STR_SET, "set") \
639+
_(ZEND_STR_MEMORY_LIMIT, "memory_limit") \
639640
_(ZEND_STR_8_DOT_0, "8.0") \
640641
_(ZEND_STR_8_DOT_1, "8.1") \
641642
_(ZEND_STR_8_DOT_2, "8.2") \

build/gen_stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,7 @@ class StringBuilder {
30293029
"username" => "ZEND_STR_USERNAME",
30303030
"password" => "ZEND_STR_PASSWORD",
30313031
"clone" => "ZEND_STR_CLONE",
3032+
"memory_limit" => "ZEND_STR_MEMORY_LIMIT",
30323033
'8.0' => 'ZEND_STR_8_DOT_0',
30333034
'8.1' => 'ZEND_STR_8_DOT_1',
30343035
'8.2' => 'ZEND_STR_8_DOT_2',

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ static PHP_INI_MH(OnChangeMaxMemoryLimit)
381381
return FAILURE;
382382
}
383383

384-
PG(memory_limit) = value;
385384
PG(max_memory_limit) = value;
385+
zend_alter_ini_entry(ZSTR_KNOWN(ZEND_STR_MEMORY_LIMIT), new_value, PHP_INI_ALL, stage);
386386

387387
return SUCCESS;
388388
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--TEST--
2+
FPM: GH-17951 - make sure to restore implicit memory_limit
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR}}
15+
pm = dynamic
16+
pm.max_children = 5
17+
pm.start_servers = 1
18+
pm.min_spare_servers = 1
19+
pm.max_spare_servers = 3
20+
EOT;
21+
22+
$ini = <<<EOT
23+
max_memory_limit = 100M
24+
[HOST=foo.bar]
25+
max_memory_limit = 200M
26+
[HOST=bar.foo]
27+
max_memory_limit = 300M
28+
EOT;
29+
30+
$code = <<<EOT
31+
<?php
32+
echo "Test Start\n";
33+
var_dump(ini_get('memory_limit'));
34+
echo "Test End\n";
35+
EOT;
36+
37+
$tester = new FPM\Tester($cfg, $code);
38+
$tester->start(iniEntries: $ini);
39+
$tester->expectLogStartNotices();
40+
$tester->request()->expectBody([
41+
'Test Start',
42+
'string(4) "100M"',
43+
'Test End'
44+
]);
45+
$tester->request(headers: [ "SERVER_NAME" => "foo.bar" ])->expectBody([
46+
'Test Start',
47+
'string(4) "200M"',
48+
'Test End'
49+
]);
50+
$tester->request(headers: [ "SERVER_NAME" => "bar.foo" ])->expectBody([
51+
'Test Start',
52+
'string(4) "300M"',
53+
'Test End'
54+
]);
55+
# check if the ini value has been reset
56+
$tester->request()->expectBody([
57+
'Test Start',
58+
'string(4) "100M"',
59+
'Test End'
60+
]);
61+
$tester->terminate();
62+
$tester->expectLogTerminatingNotices();
63+
$tester->close();
64+
65+
?>
66+
Done
67+
--EXPECT--
68+
Done
69+
--CLEAN--
70+
<?php
71+
require_once "tester.inc";
72+
FPM\Tester::clean();
73+
?>

0 commit comments

Comments
 (0)