xref: /PHP-8.2/Zend/tests/fibers/signal-async.phpt (revision 2bc6025c)
1--TEST--
2Prevent switching fibers when async signals are enabled
3--EXTENSIONS--
4pcntl
5posix
6--FILE--
7<?php
8
9pcntl_async_signals(true);
10
11pcntl_signal(SIGUSR1, function (): void {
12    if (Fiber::getCurrent() !== null) {
13        Fiber::suspend();
14    }
15});
16
17$fiber = new Fiber(function (): void {
18    echo "Fiber start\n";
19    posix_kill(posix_getpid(), SIGUSR1);
20    time_nanosleep(1);
21    echo "Fiber end\n";
22});
23
24$fiber->start();
25
26?>
27--EXPECTF--
28Fiber start
29
30Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %ssignal-async.php:%d
31Stack trace:
32#0 %ssignal-async.php(%d): Fiber::suspend()
33#1 %ssignal-async.php(%d): {closure}(%d, Array)
34#2 [internal function]: {closure}()
35#3 %ssignal-async.php(%d): Fiber->start()
36#4 {main}
37  thrown in %ssignal-async.php on line %d
38