1
0
mirror of https://github.com/php/php-src.git synced 2026-04-03 14:12:38 +02:00
Files
archived-php-src/sapi/cli/tests/php_cli_server_pdeathsig.phpt
Ilija Tovilo 5cb9e72feb Fix pdeathsig test on FreeBSD
For FreeBSD a small usleep is required to make sure the processes have
time to terminate.

Closes GH-9506
2022-09-08 16:07:06 +02:00

49 lines
1.3 KiB
PHP

--TEST--
Killing server should terminate all worker processes
--ENV--
PHP_CLI_SERVER_WORKERS=2
--SKIPIF--
<?php
include "skipif.inc";
if (!(str_contains(PHP_OS, 'Linux') || str_contains(PHP_OS, 'FreeBSD'))) {
die('skip PDEATHSIG is only supported on Linux and FreeBSD');
}
?>
--FILE--
<?php
function split_words(?string $lines): array {
return preg_split('(\s)', trim($lines ?? ''), flags: PREG_SPLIT_NO_EMPTY);
}
function find_workers_by_ppid(string $ppid) {
return split_words(shell_exec('pgrep -P ' . $ppid));
}
function find_workers_by_pids(array $pids) {
return split_words(shell_exec('ps -o pid= -p ' . join(',', $pids)));
}
include "php_cli_server.inc";
$cliServerInfo = php_cli_server_start('');
$master = proc_get_status($cliServerInfo->processHandle)['pid'];
$workersBefore = find_workers_by_ppid($master);
if (count($workersBefore) === 0) {
throw new \Exception('Could not find worker pids');
}
proc_terminate($cliServerInfo->processHandle, 9); // SIGKILL
usleep(10000);
$workersAfter = find_workers_by_pids($workersBefore);
if (count($workersAfter) !== 0) {
throw new \Exception('Workers were not properly terminated. Before: ' . join(', ', $workersBefore) . ', after: ' . join(', ', $workersAfter));
}
echo 'Done';
?>
--EXPECT--
Done