Skip to content

Commit 8feb121

Browse files
bug symfony#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
2 parents 1da85a2 + 380a54f commit 8feb121

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/Symfony/Component/Process/Pipes/UnixPipes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function readAndWrite($blocking, $close = false)
102102
unset($r[0]);
103103

104104
// let's have a look if something changed in streams
105-
if ($r && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
105+
if (($r || $w) && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
106106
// if a system call has been interrupted, forget about it, let's try again
107107
// otherwise, an error occurred, let's reset pipes
108108
if (!$this->hasSystemCallBeenInterrupted()) {

src/Symfony/Component/Process/Pipes/WindowsPipes.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ public function getFiles()
106106
public function readAndWrite($blocking, $close = false)
107107
{
108108
$this->unblock();
109-
$this->write();
110-
111-
$read = array();
112-
if ($this->fileHandles && $blocking) {
113-
usleep(Process::TIMEOUT_PRECISION * 1E6);
109+
$w = $this->write();
110+
$read = $r = $e = array();
111+
112+
if ($blocking) {
113+
if ($w) {
114+
@stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6);
115+
} elseif ($this->fileHandles) {
116+
usleep(Process::TIMEOUT_PRECISION * 1E6);
117+
}
114118
}
115119
foreach ($this->fileHandles as $type => $fileHandle) {
116120
$data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]);

src/Symfony/Component/Process/Process.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ public function wait($callback = null)
360360
do {
361361
$this->checkTimeout();
362362
$running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
363-
$close = '\\' !== DIRECTORY_SEPARATOR || !$running;
364-
$this->readPipes(true, $close);
363+
$this->readPipes($running, '\\' !== DIRECTORY_SEPARATOR || !$running);
365364
} while ($running);
366365

367366
while ($this->isRunning()) {
@@ -1295,14 +1294,15 @@ protected function updateStatus($blocking)
12951294
}
12961295

12971296
$this->processInformation = proc_get_status($this->process);
1297+
$running = $this->processInformation['running'];
12981298

1299-
$this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
1299+
$this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running);
13001300

13011301
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
13021302
$this->processInformation = $this->fallbackStatus + $this->processInformation;
13031303
}
13041304

1305-
if (!$this->processInformation['running']) {
1305+
if (!$running) {
13061306
$this->close();
13071307
}
13081308
}

0 commit comments

Comments
 (0)