-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Process] Add support for Fiber #43678
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
base: 7.3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
7.1 | ||
--- | ||
|
||
* Add support for `Fiber` | ||
|
||
6.4 | ||
--- | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -429,12 +429,31 @@ public function wait(?callable $callback = null): int | |||||||||||||
do { | ||||||||||||||
$this->checkTimeout(); | ||||||||||||||
$running = $this->isRunning() && ('\\' === \DIRECTORY_SEPARATOR || $this->processPipes->areOpen()); | ||||||||||||||
$this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running); | ||||||||||||||
if ($fiber = \Fiber::getCurrent()) { | ||||||||||||||
$this->readPipes(false, '\\' !== \DIRECTORY_SEPARATOR || !$running); | ||||||||||||||
$startedAt = microtime(true); | ||||||||||||||
$fiber->suspend(); | ||||||||||||||
$sleepFor = (int) (1000 - (microtime(true) - $startedAt) * 1000000); | ||||||||||||||
if (0 < $sleepFor) { | ||||||||||||||
Comment on lines
+434
to
+437
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (same below)
Suggested change
But I would also make readPipe return true/false whether the process did yield some activity or not. This way, we won't force a sleep while there are things to do. |
||||||||||||||
usleep($sleepFor); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it could use stream_select on the pipes instead of usleep ? so it would directly read / write if there is something to do instead of sleeping ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do use stream_select already so I guess we added this to address a situation where stream_select doesn't apply. git blame could help remember :) |
||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
$this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running); | ||||||||||||||
} | ||||||||||||||
} while ($running); | ||||||||||||||
|
||||||||||||||
while ($this->isRunning()) { | ||||||||||||||
$this->checkTimeout(); | ||||||||||||||
usleep(1000); | ||||||||||||||
if ($fiber = \Fiber::getCurrent()) { | ||||||||||||||
$startedAt = microtime(true); | ||||||||||||||
$fiber->suspend(); | ||||||||||||||
lyrixx marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
$sleepFor = (int) (1000 - (microtime(true) - $startedAt) * 1000000); | ||||||||||||||
if (0 < $sleepFor) { | ||||||||||||||
usleep($sleepFor); | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
usleep(1000); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) { | ||||||||||||||
|
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 believe there should be an additional flag to enable this support otherwise it would be a bc break for people already using this method in a
Fiber