Skip to content

Commit 16413ff

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: [Process] Revert change [Process] Fix #8746 : slowness added in unit tests since #8741
2 parents 1101801 + b146f75 commit 16413ff

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function start($callback = null)
261261
stream_set_blocking($pipe, false);
262262
}
263263

264-
$this->writePipes(false);
264+
$this->writePipes();
265265
$this->updateStatus(false);
266266
$this->checkTimeout();
267267
}
@@ -313,9 +313,9 @@ public function wait($callback = null)
313313
if (null !== $callback) {
314314
$this->callback = $this->buildCallback($callback);
315315
}
316-
while ($this->processInformation['running']) {
317-
$this->updateStatus(true);
316+
while ($this->pipes || (defined('PHP_WINDOWS_VERSION_BUILD') && $this->fileHandles)) {
318317
$this->checkTimeout();
318+
$this->readPipes(true);
319319
}
320320
$this->updateStatus(false);
321321
if ($this->processInformation['signaled']) {
@@ -1162,23 +1162,7 @@ private function readPipes($blocking)
11621162
return;
11631163
}
11641164

1165-
foreach ($r as $pipe) {
1166-
$type = array_search($pipe, $this->pipes);
1167-
$data = fread($pipe, 8192);
1168-
1169-
if (strlen($data) > 0) {
1170-
// last exit code is output and caught to work around --enable-sigchild
1171-
if (3 == $type) {
1172-
$this->fallbackExitcode = (int) $data;
1173-
} else {
1174-
call_user_func($this->callback, $type == 1 ? self::OUT : self::ERR, $data);
1175-
}
1176-
}
1177-
if (false === $data || feof($pipe)) {
1178-
fclose($pipe);
1179-
unset($this->pipes[$type]);
1180-
}
1181-
}
1165+
$this->processReadPipes($r);
11821166
}
11831167
}
11841168

@@ -1187,7 +1171,7 @@ private function readPipes($blocking)
11871171
*
11881172
* @param Boolean $blocking Whether to use blocking calls or not.
11891173
*/
1190-
private function writePipes($blocking)
1174+
private function writePipes()
11911175
{
11921176
if ($this->tty) {
11931177
$this->status = self::STATUS_TERMINATED;
@@ -1208,7 +1192,11 @@ private function writePipes($blocking)
12081192
$stdinOffset = 0;
12091193

12101194
while ($writePipes) {
1211-
$r = array();
1195+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
1196+
$this->processFileHandles();
1197+
}
1198+
1199+
$r = $this->pipes;
12121200
$w = $writePipes;
12131201
$e = null;
12141202

@@ -1235,6 +1223,34 @@ private function writePipes($blocking)
12351223
$writePipes = null;
12361224
}
12371225
}
1226+
1227+
$this->processReadPipes($r);
1228+
}
1229+
}
1230+
1231+
/**
1232+
* Processes read pipes, executes callback on it.
1233+
*
1234+
* @param array $pipes
1235+
*/
1236+
private function processReadPipes(array $pipes)
1237+
{
1238+
foreach ($pipes as $pipe) {
1239+
$type = array_search($pipe, $this->pipes);
1240+
$data = fread($pipe, 8192);
1241+
1242+
if (strlen($data) > 0) {
1243+
// last exit code is output and caught to work around --enable-sigchild
1244+
if (3 == $type) {
1245+
$this->fallbackExitcode = (int) $data;
1246+
} else {
1247+
call_user_func($this->callback, $type == 1 ? self::OUT : self::ERR, $data);
1248+
}
1249+
}
1250+
if (false === $data || feof($pipe)) {
1251+
fclose($pipe);
1252+
unset($this->pipes[$type]);
1253+
}
12381254
}
12391255
}
12401256
}

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public function testPhpDeadlock()
399399

400400
// Sleep doesn't work as it will allow the process to handle signals and close
401401
// file handles from the other end.
402-
$process = $this->getProcess('php -r "sleep 4"');
402+
$process = $this->getProcess('php -r "while (true) {}"');
403403
$process->start();
404404

405405
// PHP will deadlock when it tries to cleanup $process

0 commit comments

Comments
 (0)