bug #18150 [Process] Wait a bit less on Windows (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[Process] Wait a bit less on Windows
| Q | A
| ------------- | ---
| Branch | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
By using `stream_select` instead of `usleep` when the input is at wait, and by not blocking when the process has halted, we can enhance a bit the performance on Windows.
Commits
-------
380a54f
[Process] Wait a bit less on Windows
This commit is contained in:
commit
8feb12184c
@ -102,7 +102,7 @@ class UnixPipes extends AbstractPipes
|
|||||||
unset($r[0]);
|
unset($r[0]);
|
||||||
|
|
||||||
// let's have a look if something changed in streams
|
// let's have a look if something changed in streams
|
||||||
if ($r && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
|
if (($r || $w) && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
|
||||||
// if a system call has been interrupted, forget about it, let's try again
|
// if a system call has been interrupted, forget about it, let's try again
|
||||||
// otherwise, an error occurred, let's reset pipes
|
// otherwise, an error occurred, let's reset pipes
|
||||||
if (!$this->hasSystemCallBeenInterrupted()) {
|
if (!$this->hasSystemCallBeenInterrupted()) {
|
||||||
|
@ -106,11 +106,15 @@ class WindowsPipes extends AbstractPipes
|
|||||||
public function readAndWrite($blocking, $close = false)
|
public function readAndWrite($blocking, $close = false)
|
||||||
{
|
{
|
||||||
$this->unblock();
|
$this->unblock();
|
||||||
$this->write();
|
$w = $this->write();
|
||||||
|
$read = $r = $e = array();
|
||||||
|
|
||||||
$read = array();
|
if ($blocking) {
|
||||||
if ($this->fileHandles && $blocking) {
|
if ($w) {
|
||||||
usleep(Process::TIMEOUT_PRECISION * 1E6);
|
@stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6);
|
||||||
|
} elseif ($this->fileHandles) {
|
||||||
|
usleep(Process::TIMEOUT_PRECISION * 1E6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
foreach ($this->fileHandles as $type => $fileHandle) {
|
foreach ($this->fileHandles as $type => $fileHandle) {
|
||||||
$data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]);
|
$data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]);
|
||||||
|
@ -360,8 +360,7 @@ class Process
|
|||||||
do {
|
do {
|
||||||
$this->checkTimeout();
|
$this->checkTimeout();
|
||||||
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
|
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
|
||||||
$close = '\\' !== DIRECTORY_SEPARATOR || !$running;
|
$this->readPipes($running, '\\' !== DIRECTORY_SEPARATOR || !$running);
|
||||||
$this->readPipes(true, $close);
|
|
||||||
} while ($running);
|
} while ($running);
|
||||||
|
|
||||||
while ($this->isRunning()) {
|
while ($this->isRunning()) {
|
||||||
@ -1295,14 +1294,15 @@ class Process
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->processInformation = proc_get_status($this->process);
|
$this->processInformation = proc_get_status($this->process);
|
||||||
|
$running = $this->processInformation['running'];
|
||||||
|
|
||||||
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
|
$this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running);
|
||||||
|
|
||||||
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
||||||
$this->processInformation = $this->fallbackStatus + $this->processInformation;
|
$this->processInformation = $this->fallbackStatus + $this->processInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->processInformation['running']) {
|
if (!$running) {
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user