@@ -474,7 +474,7 @@ public function getOutput()
474
474
475
475
$ this ->readPipes (false , '\\' === DIRECTORY_SEPARATOR ? !$ this ->processInformation ['running ' ] : true );
476
476
477
- return $ this ->stdout ;
477
+ return ( string ) stream_get_contents ( $ this ->stdout , - 1 , 0 ) ;
478
478
}
479
479
480
480
/**
@@ -490,17 +490,14 @@ public function getOutput()
490
490
*/
491
491
public function getIncrementalOutput ()
492
492
{
493
- $ this ->requireProcessIsStarted (__FUNCTION__ );
494
-
495
- $ data = $ this ->getOutput ();
496
-
497
- $ latest = substr ($ data , $ this ->incrementalOutputOffset );
498
-
499
- if (false === $ latest ) {
500
- return '' ;
493
+ if ($ this ->outputDisabled ) {
494
+ throw new LogicException ('Output has been disabled. ' );
501
495
}
502
496
503
- $ this ->incrementalOutputOffset = strlen ($ data );
497
+ $ this ->requireProcessIsStarted (__FUNCTION__ );
498
+
499
+ $ latest = (string ) stream_get_contents ($ this ->stdout , -1 , $ this ->incrementalOutputOffset );
500
+ $ this ->incrementalOutputOffset = ftell ($ this ->stdout );
504
501
505
502
return $ latest ;
506
503
}
@@ -512,7 +509,8 @@ public function getIncrementalOutput()
512
509
*/
513
510
public function clearOutput ()
514
511
{
515
- $ this ->stdout = '' ;
512
+ ftruncate ($ this ->stdout , 0 );
513
+ fseek ($ this ->stdout , 0 );
516
514
$ this ->incrementalOutputOffset = 0 ;
517
515
518
516
return $ this ;
@@ -536,7 +534,7 @@ public function getErrorOutput()
536
534
537
535
$ this ->readPipes (false , '\\' === DIRECTORY_SEPARATOR ? !$ this ->processInformation ['running ' ] : true );
538
536
539
- return $ this ->stderr ;
537
+ return ( string ) stream_get_contents ( $ this ->stderr , - 1 , 0 ) ;
540
538
}
541
539
542
540
/**
@@ -553,17 +551,14 @@ public function getErrorOutput()
553
551
*/
554
552
public function getIncrementalErrorOutput ()
555
553
{
556
- $ this ->requireProcessIsStarted (__FUNCTION__ );
557
-
558
- $ data = $ this ->getErrorOutput ();
559
-
560
- $ latest = substr ($ data , $ this ->incrementalErrorOutputOffset );
561
-
562
- if (false === $ latest ) {
563
- return '' ;
554
+ if ($ this ->outputDisabled ) {
555
+ throw new LogicException ('Output has been disabled. ' );
564
556
}
565
557
566
- $ this ->incrementalErrorOutputOffset = strlen ($ data );
558
+ $ this ->requireProcessIsStarted (__FUNCTION__ );
559
+
560
+ $ latest = (string ) stream_get_contents ($ this ->stderr , -1 , $ this ->incrementalErrorOutputOffset );
561
+ $ this ->incrementalErrorOutputOffset = ftell ($ this ->stderr );
567
562
568
563
return $ latest ;
569
564
}
@@ -575,7 +570,8 @@ public function getIncrementalErrorOutput()
575
570
*/
576
571
public function clearErrorOutput ()
577
572
{
578
- $ this ->stderr = '' ;
573
+ ftruncate ($ this ->stderr , 0 );
574
+ fseek ($ this ->stderr , 0 );
579
575
$ this ->incrementalErrorOutputOffset = 0 ;
580
576
581
577
return $ this ;
@@ -795,23 +791,31 @@ public function stop($timeout = 10, $signal = null)
795
791
/**
796
792
* Adds a line to the STDOUT stream.
797
793
*
794
+ * @internal
795
+ *
798
796
* @param string $line The line to append
799
797
*/
800
798
public function addOutput ($ line )
801
799
{
802
800
$ this ->lastOutputTime = microtime (true );
803
- $ this ->stdout .= $ line ;
801
+ fseek ($ this ->stdout , 0 , SEEK_END );
802
+ fwrite ($ this ->stdout , $ line );
803
+ fseek ($ this ->stdout , $ this ->incrementalOutputOffset );
804
804
}
805
805
806
806
/**
807
807
* Adds a line to the STDERR stream.
808
808 *
809
+ * @internal
810
+ *
809
811
* @param string $line The line to append
810
812
*/
811
813
public function addErrorOutput ($ line )
812
814
{
813
815
$ this ->lastOutputTime = microtime (true );
814
- $ this ->stderr .= $ line ;
816
+ fseek ($ this ->stderr , 0 , SEEK_END );
817
+ fwrite ($ this ->stderr , $ line );
818
+ fseek ($ this ->stderr , $ this ->incrementalErrorOutputOffset );
815
819
}
816
820
817
821
/**
@@ -1393,8 +1397,8 @@ private function resetProcessData()
1393
1397
$ this ->exitcode = null ;
1394
1398
$ this ->fallbackStatus = array ();
1395
1399
$ this ->processInformation = null ;
1396
- $ this ->stdout = null ;
1397
- $ this ->stderr = null ;
1400
+ $ this ->stdout = fopen ( ' php://temp/maxmemory: ' .( 8 * 1024 * 1024 ), ' a+ ' ) ;
1401
+ $ this ->stderr = fopen ( ' php://temp/maxmemory: ' .( 8 * 1024 * 1024 ), ' a+ ' ) ;
1398
1402
$ this ->process = null ;
1399
1403
$ this ->latestSignal = null ;
1400
1404
$ this ->status = self ::STATUS_READY ;
0 commit comments