Skip to content

Commit feb053a

Browse files
committed
Make sure to modify memory_limit value through the registered handler.
1 parent 3e3e9cb commit feb053a

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

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_INIT_LITERAL("memory_limit", 1), 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)