@@ -62,18 +62,19 @@ final class StreamSelectLoop implements LoopInterface
62
62
private $ writeListeners = array ();
63
63
private $ running ;
64
64
private $ pcntl = false ;
65
- private $ pcntlActive = false ;
65
+ private $ pcntlPoll = false ;
66
66
private $ signals ;
67
67
68
68
public function __construct ()
69
69
{
70
70
$ this ->futureTickQueue = new FutureTickQueue ();
71
71
$ this ->timers = new Timers ();
72
- $ this ->pcntl = \extension_loaded ( ' pcntl ' );
73
- $ this ->pcntlActive = $ this ->pcntl && !\function_exists ('pcntl_async_signals ' );
72
+ $ this ->pcntl = \function_exists ( ' pcntl_signal ' ) && \function_exists ( ' pcntl_signal_dispatch ' );
73
+ $ this ->pcntlPoll = $ this ->pcntl && !\function_exists ('pcntl_async_signals ' );
74
74
$ this ->signals = new SignalsHandler ();
75
75
76
- if ($ this ->pcntl && !$ this ->pcntlActive ) {
76
+ // prefer async signals if available (PHP 7.1+) or fall back to dispatching on each tick
77
+ if ($ this ->pcntl && !$ this ->pcntlPoll ) {
77
78
\pcntl_async_signals (true );
78
79
}
79
80
}
@@ -228,7 +229,7 @@ private function waitForStreamActivity($timeout)
228
229
$ write = $ this ->writeStreams ;
229
230
230
231
$ available = $ this ->streamSelect ($ read , $ write , $ timeout );
231
- if ($ this ->pcntlActive ) {
232
+ if ($ this ->pcntlPoll ) {
232
233
\pcntl_signal_dispatch ();
233
234
}
234
235
if (false === $ available ) {
0 commit comments