Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72a4d79

Browse files
committed
[Process] getIncrementalOutput should work without calling getOutput
1 parente187f8b commit72a4d79

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

‎src/Symfony/Component/Process/Process.php‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,7 @@ public function isOutputDisabled()
463463
*/
464464
publicfunctiongetOutput()
465465
{
466-
if ($this->outputDisabled) {
467-
thrownewLogicException('Output has been disabled.');
468-
}
469-
470-
$this->requireProcessIsStarted(__FUNCTION__);
471-
472-
$this->readPipes(false,'\\' ===DIRECTORY_SEPARATOR ? !$this->processInformation['running'] :true);
466+
$this->readPipesForOutput(__FUNCTION__);
473467

474468
if (false ===$ret =stream_get_contents($this->stdout, -1,0)) {
475469
return'';
@@ -491,11 +485,7 @@ public function getOutput()
491485
*/
492486
publicfunctiongetIncrementalOutput()
493487
{
494-
if ($this->outputDisabled) {
495-
thrownewLogicException('Output has been disabled.');
496-
}
497-
498-
$this->requireProcessIsStarted(__FUNCTION__);
488+
$this->readPipesForOutput(__FUNCTION__);
499489

500490
$latest =stream_get_contents($this->stdout, -1,$this->incrementalOutputOffset);
501491
$this->incrementalOutputOffset =ftell($this->stdout);
@@ -531,13 +521,7 @@ public function clearOutput()
531521
*/
532522
publicfunctiongetErrorOutput()
533523
{
534-
if ($this->outputDisabled) {
535-
thrownewLogicException('Output has been disabled.');
536-
}
537-
538-
$this->requireProcessIsStarted(__FUNCTION__);
539-
540-
$this->readPipes(false,'\\' ===DIRECTORY_SEPARATOR ? !$this->processInformation['running'] :true);
524+
$this->readPipesForOutput(__FUNCTION__);
541525

542526
if (false ===$ret =stream_get_contents($this->stderr, -1,0)) {
543527
return'';
@@ -560,11 +544,7 @@ public function getErrorOutput()
560544
*/
561545
publicfunctiongetIncrementalErrorOutput()
562546
{
563-
if ($this->outputDisabled) {
564-
thrownewLogicException('Output has been disabled.');
565-
}
566-
567-
$this->requireProcessIsStarted(__FUNCTION__);
547+
$this->readPipesForOutput(__FUNCTION__);
568548

569549
$latest =stream_get_contents($this->stderr, -1,$this->incrementalErrorOutputOffset);
570550
$this->incrementalErrorOutputOffset =ftell($this->stderr);
@@ -1328,6 +1308,24 @@ protected function isSigchildEnabled()
13281308
returnself::$sigchild =false !==strpos(ob_get_clean(),'--enable-sigchild');
13291309
}
13301310

1311+
/**
1312+
* Reads pipes for the freshest output.
1313+
*
1314+
* @param $caller The name of the method that needs fresh outputs
1315+
*
1316+
* @throw LogicException in case output has been disabled or process is not started
1317+
*/
1318+
privatefunctionreadPipesForOutput($caller)
1319+
{
1320+
if ($this->outputDisabled) {
1321+
thrownewLogicException('Output has been disabled.');
1322+
}
1323+
1324+
$this->requireProcessIsStarted($caller);
1325+
1326+
$this->readPipes(false,'\\' ===DIRECTORY_SEPARATOR ? !$this->processInformation['running'] :true);
1327+
}
1328+
13311329
/**
13321330
* Validates and returns the filtered timeout.
13331331
*

‎src/Symfony/Component/Process/Tests/ProcessTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,31 @@ public function pipesCodeProvider()
11651165
return$codes;
11661166
}
11671167

1168+
/**
1169+
* @dataProvider provideVariousIncrementals
1170+
*/
1171+
publicfunctiontestIncrementalOutputDoesNotRequiresAnotherCall($stream,$method) {
1172+
$process =newProcess(self::$phpBin." -r '\$n = 0; while (\$n < 3) { fwrite($stream,\$n, 1);\$n++; usleep(1000); }'",null,null,null,null);
1173+
$process->start();
1174+
$result ='';
1175+
$limit =microtime(true) +3;
1176+
$expected ='012';
1177+
1178+
while ($result !==$expected &&microtime(true) <$limit) {
1179+
$result .=$process->$method();
1180+
}
1181+
1182+
$this->assertSame($expected,$result);
1183+
$process->stop();
1184+
}
1185+
1186+
publicfunctionprovideVariousIncrementals() {
1187+
returnarray(
1188+
array('STDOUT','getIncrementalOutput'),
1189+
array('STDERR','getIncrementalErrorOutput'),
1190+
);
1191+
}
1192+
11681193
/**
11691194
* provides default method names for simple getter/setter.
11701195
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp