Skip to content

Commit abd56ae

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents f20e11c + d8612fb commit abd56ae

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
- FPM:
2121
. Fixed bug #76003 (FPM /status reports wrong number of active processe).
2222
(Jakub Zelenka)
23+
. Fixed bug #77023 (FPM cannot shutdown processes). (Jakub Zelenka)
2324

2425
- Hash:
2526
. Fixed bug #81714 (segfault when serializing finalized HashContext). (cmb)

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ int fpm_pctl_kill(pid_t pid, int how) /* {{{ */
138138
case FPM_PCTL_QUIT :
139139
s = SIGQUIT;
140140
break;
141+
case FPM_PCTL_KILL:
142+
s = SIGKILL;
143+
break;
141144
default :
142145
break;
143146
}
@@ -313,6 +316,17 @@ static void fpm_pctl_check_request_timeout(struct timeval *now) /* {{{ */
313316
}
314317
/* }}} */
315318

319+
static void fpm_pctl_kill_idle_child(struct fpm_child_s *child) /* {{{ */
320+
{
321+
if (child->idle_kill) {
322+
fpm_pctl_kill(child->pid, FPM_PCTL_KILL);
323+
} else {
324+
child->idle_kill = 1;
325+
fpm_pctl_kill(child->pid, FPM_PCTL_QUIT);
326+
}
327+
}
328+
/* }}} */
329+
316330
static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ */
317331
{
318332
struct fpm_worker_pool_s *wp;
@@ -375,8 +389,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
375389
fpm_request_last_activity(last_idle_child, &last);
376390
fpm_clock_get(&now);
377391
if (last.tv_sec < now.tv_sec - wp->config->pm_process_idle_timeout) {
378-
last_idle_child->idle_kill = 1;
379-
fpm_pctl_kill(last_idle_child->pid, FPM_PCTL_QUIT);
392+
fpm_pctl_kill_idle_child(last_idle_child);
380393
}
381394

382395
continue;
@@ -388,8 +401,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
388401
zlog(ZLOG_DEBUG, "[pool %s] currently %d active children, %d spare children, %d running children. Spawning rate %d", wp->config->name, active, idle, wp->running_children, wp->idle_spawn_rate);
389402

390403
if (idle > wp->config->pm_max_spare_servers && last_idle_child) {
391-
last_idle_child->idle_kill = 1;
392-
fpm_pctl_kill(last_idle_child->pid, FPM_PCTL_QUIT);
404+
fpm_pctl_kill_idle_child(last_idle_child);
393405
wp->idle_spawn_rate = 1;
394406
continue;
395407
}

sapi/fpm/fpm/fpm_process_ctl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ enum {
4242
FPM_PCTL_TERM,
4343
FPM_PCTL_STOP,
4444
FPM_PCTL_CONT,
45-
FPM_PCTL_QUIT
45+
FPM_PCTL_QUIT,
46+
FPM_PCTL_KILL
4647
};
4748

4849
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
FPM: Blocked SIGQUIT prevents idle process to be killed
3+
--EXTENSIONS--
4+
pcntl
5+
--SKIPIF--
6+
<?php
7+
include "skipif.inc";
8+
if (!function_exists('pcntl_sigprocmask')) die('skip Requires pcntl_sigprocmask()');
9+
if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
10+
?>
11+
--FILE--
12+
<?php
13+
14+
require_once "tester.inc";
15+
16+
$cfg = <<<EOT
17+
[global]
18+
error_log = {{FILE:LOG}}
19+
pid = {{FILE:PID}}
20+
[unconfined]
21+
listen = {{ADDR}}
22+
pm.status_path = /status
23+
pm = dynamic
24+
pm.max_children = 2
25+
pm.start_servers = 1
26+
pm.min_spare_servers = 1
27+
pm.max_spare_servers = 1
28+
EOT;
29+
30+
$code = <<<EOT
31+
<?php
32+
pcntl_sigprocmask(SIG_BLOCK, [SIGQUIT, SIGTERM]);
33+
usleep(300000);
34+
EOT;
35+
36+
37+
$tester = new FPM\Tester($cfg, $code);
38+
$tester->start();
39+
$tester->expectLogStartNotices();
40+
$tester->multiRequest(2);
41+
$tester->status([
42+
'total processes' => 2,
43+
]);
44+
// wait for process to be killed
45+
sleep(7);
46+
$tester->expectLogWarning('child \\d+ exited on signal 9 \\(SIGKILL\\) after \\d+.\\d+ seconds from start', 'unconfined');
47+
$tester->expectLogNotice('child \\d+ started', 'unconfined');
48+
$tester->expectLogWarning('child \\d+ exited on signal 9 \\(SIGKILL\\) after \\d+.\\d+ seconds from start', 'unconfined');
49+
$tester->expectLogNotice('child \\d+ started', 'unconfined');
50+
$tester->status([
51+
'total processes' => 1,
52+
]);
53+
$tester->terminate();
54+
$tester->expectLogTerminatingNotices();
55+
$tester->close();
56+
57+
?>
58+
Done
59+
--EXPECT--
60+
Done
61+
--CLEAN--
62+
<?php
63+
require_once "tester.inc";
64+
FPM\Tester::clean();
65+
?>

0 commit comments

Comments
 (0)