xref: /PHP-8.2/ext/pcntl/tests/pcntl_signal.phpt (revision 74859783)
1--TEST--
2pcntl_signal()
3--EXTENSIONS--
4pcntl
5posix
6--FILE--
7<?php
8pcntl_signal(SIGTERM, function($signo){
9    echo "signal dispatched\n";
10});
11posix_kill(posix_getpid(), SIGTERM);
12pcntl_signal_dispatch();
13
14pcntl_signal(SIGUSR1, function($signo, $siginfo){
15    printf("got signal from %s\n", $siginfo['pid'] ?? 'nobody');
16});
17posix_kill(posix_getpid(), SIGUSR1);
18pcntl_signal_dispatch();
19
20var_dump(pcntl_signal(SIGALRM, SIG_IGN));
21
22try {
23    pcntl_signal(-1, -1);
24} catch (ValueError $exception) {
25    echo $exception->getMessage() . "\n";
26}
27
28try {
29    pcntl_signal(-1, function(){});
30} catch (ValueError $exception) {
31    echo $exception->getMessage() . "\n";
32}
33
34try {
35    pcntl_signal(SIGALRM, "not callable");
36} catch (TypeError $exception) {
37    echo $exception->getMessage() . "\n";
38}
39
40/* test freeing queue in RSHUTDOWN */
41posix_kill(posix_getpid(), SIGTERM);
42echo "ok\n";
43?>
44--EXPECTF--
45signal dispatched
46got signal from %r\d+|nobody%r
47bool(true)
48pcntl_signal(): Argument #1 ($signal) must be greater than or equal to 1
49pcntl_signal(): Argument #1 ($signal) must be greater than or equal to 1
50pcntl_signal(): Argument #2 ($handler) must be of type callable|int, string given
51ok
52