xref: /PHP-7.3/ext/pcntl/tests/pcntl_signal.phpt (revision cbb0efae)
1--TEST--
2pcntl_signal()
3--SKIPIF--
4<?php if (!extension_loaded("pcntl")) print "skip"; ?>
5<?php if (!extension_loaded("posix")) die("skip posix extension not available"); ?>
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());
21var_dump(pcntl_signal(SIGALRM, SIG_IGN));
22var_dump(pcntl_signal(-1, -1));
23var_dump(pcntl_signal(-1, function(){}));
24var_dump(pcntl_signal(SIGALRM, "not callable"));
25
26
27/* test freeing queue in RSHUTDOWN */
28posix_kill(posix_getpid(), SIGTERM);
29echo "ok\n";
30?>
31--EXPECTF--
32signal dispatched
33got signal from %r\d+|nobody%r
34
35Warning: pcntl_signal() expects at least 2 parameters, 0 given in %s
36NULL
37bool(true)
38
39Warning: pcntl_signal(): Invalid signal %s
40bool(false)
41
42Warning: pcntl_signal(): Invalid signal %s
43bool(false)
44
45Warning: pcntl_signal(): Specified handler "not callable" is not callable (%s) in %s
46bool(false)
47ok
48