merged branch romainneutron/slowness (PR #8749)
This PR was merged into the 2.2 branch. Discussion ---------- [Process] Fix #8746 : slowness added in unit tests since #8741 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8746 | License | MIT Commits -------8c4bae3
[Process] Revert change8d9c7c6
[Process] Fix #8746 : slowness added in unit tests since #8741
This commit is contained in:
commit
b146f75b3f
@ -287,7 +287,7 @@ class Process
|
|||||||
stream_set_blocking($pipe, false);
|
stream_set_blocking($pipe, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writePipes(false);
|
$this->writePipes();
|
||||||
$this->updateStatus(false);
|
$this->updateStatus(false);
|
||||||
$this->checkTimeout();
|
$this->checkTimeout();
|
||||||
}
|
}
|
||||||
@ -339,9 +339,9 @@ class Process
|
|||||||
if (null !== $callback) {
|
if (null !== $callback) {
|
||||||
$this->callback = $this->buildCallback($callback);
|
$this->callback = $this->buildCallback($callback);
|
||||||
}
|
}
|
||||||
while ($this->processInformation['running']) {
|
while ($this->pipes || (defined('PHP_WINDOWS_VERSION_BUILD') && $this->fileHandles)) {
|
||||||
$this->updateStatus(true);
|
|
||||||
$this->checkTimeout();
|
$this->checkTimeout();
|
||||||
|
$this->readPipes(true);
|
||||||
}
|
}
|
||||||
$this->updateStatus(false);
|
$this->updateStatus(false);
|
||||||
if ($this->processInformation['signaled']) {
|
if ($this->processInformation['signaled']) {
|
||||||
@ -1069,23 +1069,7 @@ class Process
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($r as $pipe) {
|
$this->processReadPipes($r);
|
||||||
$type = array_search($pipe, $this->pipes);
|
|
||||||
$data = fread($pipe, 8192);
|
|
||||||
|
|
||||||
if (strlen($data) > 0) {
|
|
||||||
// last exit code is output and caught to work around --enable-sigchild
|
|
||||||
if (3 == $type) {
|
|
||||||
$this->fallbackExitcode = (int) $data;
|
|
||||||
} else {
|
|
||||||
call_user_func($this->callback, $type == 1 ? self::OUT : self::ERR, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (false === $data || feof($pipe)) {
|
|
||||||
fclose($pipe);
|
|
||||||
unset($this->pipes[$type]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1094,7 +1078,7 @@ class Process
|
|||||||
*
|
*
|
||||||
* @param Boolean $blocking Whether to use blocking calls or not.
|
* @param Boolean $blocking Whether to use blocking calls or not.
|
||||||
*/
|
*/
|
||||||
private function writePipes($blocking)
|
private function writePipes()
|
||||||
{
|
{
|
||||||
if (null === $this->stdin) {
|
if (null === $this->stdin) {
|
||||||
fclose($this->pipes[0]);
|
fclose($this->pipes[0]);
|
||||||
@ -1109,7 +1093,11 @@ class Process
|
|||||||
$stdinOffset = 0;
|
$stdinOffset = 0;
|
||||||
|
|
||||||
while ($writePipes) {
|
while ($writePipes) {
|
||||||
$r = array();
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
$this->processFileHandles();
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = $this->pipes;
|
||||||
$w = $writePipes;
|
$w = $writePipes;
|
||||||
$e = null;
|
$e = null;
|
||||||
|
|
||||||
@ -1136,6 +1124,34 @@ class Process
|
|||||||
$writePipes = null;
|
$writePipes = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->processReadPipes($r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes read pipes, executes callback on it.
|
||||||
|
*
|
||||||
|
* @param array $pipes
|
||||||
|
*/
|
||||||
|
private function processReadPipes(array $pipes)
|
||||||
|
{
|
||||||
|
foreach ($pipes as $pipe) {
|
||||||
|
$type = array_search($pipe, $this->pipes);
|
||||||
|
$data = fread($pipe, 8192);
|
||||||
|
|
||||||
|
if (strlen($data) > 0) {
|
||||||
|
// last exit code is output and caught to work around --enable-sigchild
|
||||||
|
if (3 == $type) {
|
||||||
|
$this->fallbackExitcode = (int) $data;
|
||||||
|
} else {
|
||||||
|
call_user_func($this->callback, $type == 1 ? self::OUT : self::ERR, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (false === $data || feof($pipe)) {
|
||||||
|
fclose($pipe);
|
||||||
|
unset($this->pipes[$type]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// Sleep doesn't work as it will allow the process to handle signals and close
|
// Sleep doesn't work as it will allow the process to handle signals and close
|
||||||
// file handles from the other end.
|
// file handles from the other end.
|
||||||
$process = $this->getProcess('php -r "sleep 4"');
|
$process = $this->getProcess('php -r "while (true) {}"');
|
||||||
$process->start();
|
$process->start();
|
||||||
|
|
||||||
// PHP will deadlock when it tries to cleanup $process
|
// PHP will deadlock when it tries to cleanup $process
|
||||||
|
Reference in New Issue
Block a user