8000 Check PCNTL functions for signal support instead of PCNTL extension · reactphp/event-loop@f80ace6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f80ace6

Browse files
committed
Check PCNTL functions for signal support instead of PCNTL extension
This helps avoiding problems when the PCNTL extension is loaded, but (some of) its functions are disabled via PHPs `disable_function` configuration. This is particularly common for the PCNTL functions in CGI environments, e.g. they are disabled by default on Debian- / Ubuntu-based distributions. Previously, even when not attaching any signal listeners, the loop would print a warning on each loop tick: > PHP Warning: pcntl_signal_dispatch() has been disabled for security reasons in {file} on {line}
1 parent a0ecac9 commit f80ace6

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)
0