-
-
Notifications
You must be signed in to change notification settings - Fork 132
Implement ExtEvLoop (PECL ext-ev) #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey @kaduev13 yes your PR is still wanted, in fact the plan was to take over and finish your PR once |
405cb25
to
41018f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaduev13 Thank you so much for keeping up with this and filing an update! 👍
I've found some minor issues below, otherwise LGTM 👍
src/ExtEvLoop.php
Outdated
}, | ||
function ($signal) { | ||
if ($this->signals->count($signal) === 0) { | ||
unset($this->signalEvents[$signal]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably stop()
the watcher before clearing this reference, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's very important to stop watcher before clearing the reference. Fixed.
src/ExtEvLoop.php
Outdated
private function getStreamListenerClosure($stream, callable $listener) | ||
{ | ||
return function () use ($stream, $listener) { | ||
call_user_func($listener, $stream, $this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The additional $loop
argument has been removed via #110, so the last parameter should be omitted here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing it! I removed this argument.
src/Factory.php
Outdated
} elseif (class_exists('EvLoop', false)) { | ||
return new ExtEvLoop(); | ||
} | ||
elseif (class_exists('EventBase', false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor CS issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thank you :)
tests/AbstractLoopTest.php
Outdated
$this->loop->removeSignal(SIGUSR1, $function); | ||
$this->loop->stop(); | ||
}); | ||
|
||
$this->assertRunSlowerThan(1.5); | ||
$this->assertRunSlowerThan(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that there was a problem with floating point accuracy, but it was not. It should be changed to the previous 1.5
value. Fixed.
97d946c
to
8aef041
Compare
Also, I noticed that other loops implementations contains such code for signals callbacks: function ($signal) {
$this->signalEvents[$signal] = new SignalEvent($f = function () use ($signal, &$f) {
$this->signals->call($signal);
// Ensure there are two copies of the callable around until it has been executed.
// For more information see: https://bugs.php.net/bug.php?id=62452
// Only an issue for PHP 5, this hack can be removed once PHP 5 support has been dropped.
$g = $f;
$f = $g;
}, $signal);
$this->loop->add($this->signalEvents[$signal]);
}, My question is why using the function ($signal) {
$this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
$this->signals->call($signal);
}, $signal);
$this->loop->add($this->signalEvents[$signal]);
} |
@kaduev13 The issue in PHP 5.x is that the callable we're calling |
@WyriHaximus, I checked that issue, but, as I understood, this bug is about aliasing. I mean, that this code will randomly fail: function ($signal) {
$this->signalEvents[$signal] = new SignalEvent($f = function () use ($signal, &$f) {
$this->signals->call($signal);
}, $signal);
$this->loop->add($this->signalEvents[$signal]);
} but this one should not (no alias == no problems?): function ($signal) {
$this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
$this->signals->call($signal);
}, $signal);
$this->loop->add($this->signalEvents[$signal]);
} |
@kaduev13 feel free to prove me wrong, I don't like the solution for that bug so if we can get rid of it that would be great 👍 . Also be sure to check signal example to be sure. IIRC this is one of the failing builds for that bug: https://travis-ci.org/reactphp/event-loop/jobs/258431073#L1054 |
@WyriHaximus, thank you! Unfortunately, the build url you provided is for commit, that does not exist. I'll try to reproduce this behavior. |
@kaduev13 yes correct/sorry about that the commits where squashed just before merging to keep a clean commit log. |
@WyriHaximus sorry, I didn't have enough time to completely test the issue with lambdas. I'll continue my investigation later. I added similar workaround to |
@kaduev13 Very good point about signal handling callbacks! I've just filed #150, once this is in, this should be simplified significantly (this will likely cause a merge conflict here though). |
12d714f
to
242fc11
Compare
@clue nice work with signals, thank you! I rebased this branch onto master, review pls =) |
ExtEvLoop implements event loop based on PECL ev extension.
242fc11
to
b325a88
Compare
52bbf89
to
43dc6ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaduev13 Again, thank you so much for keeping up with this and putting the effort into keeping this updated! 👍
Only this one minor remark, otherwise I'm happy to get this in finally! 🎉
src/ExtEvLoop.php
Outdated
public function isTimerActive(TimerInterface $timer) | ||
{ | ||
return $this->timers->contains($timer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method has been removed from the public interface with #133, so this should probably be removed here.
@@ -201,6 +201,16 @@ It supports the same backends as libevent. | |||
|
|||
This loop is known to work with PHP 5.4 through PHP 7+. | |||
|
|||
#### ExtEvLoop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be added to the TOC above 👍
@clue thank you for the review :) I fixed these issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for the update! 🎉
Awesome, thank you 👍 ! |
Great to know that it's merged! Thank you! |
@kaduev13 |
@kaduev13 FYI I've been running it in production for a week now, as expected no issue what so ever. Well done 👍 |
@clue, @WyriHaximus, @jsor hello!
Finally I fixed my old pull request. I'm really sorry that it took so long for me.
I hope, that this feature still wanted and needed :)