[Process] Fix latest merge from 2.2 in 2.3

This commit is contained in:
Romain Neutron 2013-10-09 23:17:57 +02:00
parent 77a961d040
commit b5e3576ea0

View File

@ -298,21 +298,18 @@ class Process
if (null !== $callback) { if (null !== $callback) {
$this->callback = $this->buildCallback($callback); $this->callback = $this->buildCallback($callback);
} }
do { do {
$this->checkTimeout(); $this->checkTimeout();
$running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles(); $running = defined('PHP_WINDOWS_VERSION_BUILD') ? $this->isRunning() : $this->processPipes->hasOpenHandles();
$close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;; $close = !defined('PHP_WINDOWS_VERSION_BUILD') || !$running;;
$this->readPipes(true, $close); $this->readPipes(true, $close);
} while ($running); } while ($running);
while ($this->isRunning()) { while ($this->isRunning()) {
usleep(1000); usleep(1000);
} }
$this->processPipes->close();
$exitcode = proc_close($this->process);
if ($this->processInformation['signaled']) { if ($this->processInformation['signaled']) {
if ($this->isSigchildEnabled()) { if ($this->isSigchildEnabled()) {
throw new RuntimeException('The process has been signaled.'); throw new RuntimeException('The process has been signaled.');
@ -1043,7 +1040,7 @@ class Process
} else { } else {
$result = $this->processPipes->read($blocking); $result = $this->processPipes->read($blocking);
} }
foreach ($result as $type => $data) { foreach ($result as $type => $data) {
if (3 == $type) { if (3 == $type) {
$this->fallbackExitcode = (int) $data; $this->fallbackExitcode = (int) $data;
@ -1073,27 +1070,11 @@ class Process
{ {
$exitcode = -1; $exitcode = -1;
$this->processPipes->close();
if (is_resource($this->process)) { if (is_resource($this->process)) {
// Unix pipes must be closed before calling proc_close to void deadlock
// see manual http://php.net/manual/en/function.proc-close.php
$this->processPipes->closeUnixPipes();
$exitcode = proc_close($this->process); $exitcode = proc_close($this->process);
} }
// Windows only : when using file handles, some activity may occur after
// calling proc_close
while ($this->processPipes->hasOpenHandles()) {
usleep(100);
foreach ($this->processPipes->readAndCloseHandles(true) as $type => $data) {
if (3 == $type) {
$this->fallbackExitcode = (int) $data;
} else {
call_user_func($this->callback, $type === self::STDOUT ? self::OUT : self::ERR, $data);
}
}
}
$this->processPipes->close();
$this->exitcode = $this->exitcode !== null ? $this->exitcode : -1; $this->exitcode = $this->exitcode !== null ? $this->exitcode : -1;
$this->exitcode = -1 != $exitcode ? $exitcode : $this->exitcode; $this->exitcode = -1 != $exitcode ? $exitcode : $this->exitcode;