|
| 1 | +--TEST-- |
| 2 | +Killing server should terminate all worker processes |
| 3 | +--ENV-- |
| 4 | +PHP_CLI_SERVER_WORKERS=2 |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +include "skipif.inc"; |
| 8 | +if (!(str_contains(PHP_OS, 'Linux') || str_contains(PHP_OS, 'FreeBSD'))) { |
| 9 | + die('skip PDEATHSIG is only supported on Linux and FreeBSD'); |
| 10 | +} |
| 11 | +?> |
| 12 | +--FILE-- |
| 13 | +<?php |
| 14 | + |
| 15 | +function split_words(?string $lines): array { |
| 16 | + return preg_split('(\s)', trim($lines ?? ''), flags: PREG_SPLIT_NO_EMPTY); |
| 17 | +} |
| 18 | + |
| 19 | +function find_workers_by_ppid(string $ppid) { |
| 20 | + return split_words(shell_exec('pgrep -P ' . $ppid)); |
| 21 | +} |
| 22 | + |
| 23 | +function find_workers_by_pids(array $pids) { |
| 24 | + return split_words(shell_exec('ps -o pid= -p ' . join(',', $pids))); |
| 25 | +} |
| 26 | + |
| 27 | +include "php_cli_server.inc"; |
| 28 | +$cliServerInfo = php_cli_server_start(''); |
| 29 | + |
| 30 | +$master = proc_get_status($cliServerInfo->processHandle)['pid']; |
| 31 | +$workers = find_workers_by_ppid($master); |
| 32 | +if (count($workers) === 0) { |
| 33 | + throw new \Exception('Could not find worker pids'); |
| 34 | +} |
| 35 | + |
| 36 | +proc_terminate($cliServerInfo->processHandle, 9); // SIGKILL |
| 37 | + |
| 38 | +$workers = find_workers_by_pids($workers); |
| 39 | +if (count($workers) !== 0) { |
| 40 | + throw new \Exception('Workers were not properly terminated'); |
| 41 | +} |
| 42 | + |
| 43 | +echo 'Done'; |
| 44 | +?> |
| 45 | +--EXPECT-- |
| 46 | +Done |
0 commit comments