phasync
phasync / onSignal

Method

phasync::onSignal

Run $handler the moment $signo arrives, inside the signal handler: with pcntl_async_signals(true) in the middle of whatever is executing, even a coroutine that never yields; otherwise when the event loop dispatches signals. For what must happen at that moment, such as logging where a stuck process is; it must not suspend (no await, sleep or phasync I/O). Coroutines in phasync::signal are woken for the same signal as well. phasync takes the signal over until the outermost phasync::run() returns (a previous pcntl_signal() handler is called as well, and put back then), so register it for a run.

Description#

public static phasync::onSignal(
    int $signo,
    Closure $handler
): void

Parameters#

$signo int
$handler Closure
Called with the signal number

Examples#

Example 1
phasync::onSignal(SIGQUIT, function () {
    error_log('stuck at ' . (new Exception())->getTraceAsString());
});