pcntl_signal.phpt 1.2 KB

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