Skip to content

Commit

Permalink
Explicitly keep track of stream resources for ExtEventLoop on PHP7+
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Dec 1, 2017
1 parent 04f7ca6 commit 4dd1532
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ExtEventLoop implements LoopInterface
private $streamCallback;
private $streamEvents = [];
private $streamFlags = [];
private $streamRefs = [];
private $readListeners = [];
private $writeListeners = [];
private $running;
Expand Down Expand Up @@ -110,7 +111,8 @@ private function removeStream($stream)
$this->streamFlags[$key],
$this->streamEvents[$key],
$this->readListeners[$key],
$this->writeListeners[$key]
$this->writeListeners[$key],
$this->streamRefs[$key]
);
}
}
Expand Down Expand Up @@ -224,6 +226,12 @@ private function subscribeStreamEvent($stream, $flag)

$this->streamEvents[$key] = $event;
$this->streamFlags[$key] = $flag;

// ext-event does not increase refcount on stream resources for PHP 7+
// manually keep track of stream resource to prevent premature garbage collection
if (PHP_VERSION_ID >= 70000) {
$this->streamRefs[$key] = $stream;
}
}

$event->add();
Expand Down

0 comments on commit 4dd1532

Please sign in to comment.