Skip to content

Commit 060092e

Browse files
authored
Check PCNTL functions for signal support instead of PCNTL extension (#195)
Check PCNTL functions for signal support instead of PCNTL extension
2 parents a0ecac9 + f80ace6 commit 060092e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/StreamSelectLoop.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ final class StreamSelectLoop implements LoopInterface
6262
private $writeListeners = array();
6363
private $running;
6464
private $pcntl = false;
65-
private $pcntlActive = false;
65+
private $pcntlPoll = false;
6666
private $signals;
6767

6868
public function __construct()
6969
{
7070
$this->futureTickQueue = new FutureTickQueue();
7171
$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');
7474
$this->signals = new SignalsHandler();
7575

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) {
7778
\pcntl_async_signals(true);
7879
}
7980
}
@@ -228,7 +229,7 @@ private function waitForStreamActivity($timeout)
228229
$write = $this->writeStreams;
229230

230231
$available = $this->streamSelect($read, $write, $timeout);
231-
if ($this->pcntlActive) {
232+
if ($this->pcntlPoll) {
232233
\pcntl_signal_dispatch();
233234
}
234235
if (false === $available) {

0 commit comments

Comments
 (0)