From 0dc6539900198624ad5d9aede7f2b7137a834461 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 29 Nov 2021 14:26:29 +0000 Subject: [PATCH] [1.x] Fixes Octane's process output not being flushed (#428) * Fixes issue where `php://temp` may be full * Update InteractsWithServers.php Co-authored-by: Taylor Otwell --- src/Commands/Concerns/InteractsWithServers.php | 13 +++++++++++++ src/Commands/StartRoadRunnerCommand.php | 6 ++++-- src/Commands/StartSwooleCommand.php | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index 4950d1672..fb23ee1ef 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -106,6 +106,19 @@ protected function writeServerRunningMessage() ]); } + /** + * Retrieve the given server output and flush it. + * + * @return array + */ + protected function getServerOutput($server) + { + return tap([ + $server->getIncrementalOutput(), + $server->getIncrementalErrorOutput(), + ], fn () => $server->clearOutput()->clearErrorOutput()); + } + /** * Returns the list of signals to subscribe. * diff --git a/src/Commands/StartRoadRunnerCommand.php b/src/Commands/StartRoadRunnerCommand.php index faec8fc53..4e4037c0e 100644 --- a/src/Commands/StartRoadRunnerCommand.php +++ b/src/Commands/StartRoadRunnerCommand.php @@ -182,7 +182,9 @@ protected function rpcPort() */ protected function writeServerOutput($server) { - Str::of($server->getIncrementalOutput()) + [$output, $errorOutput] = $this->getServerOutput($server); + + Str::of($output) ->explode("\n") ->filter() ->each(function ($output) { @@ -210,7 +212,7 @@ protected function writeServerOutput($server) } }); - Str::of($server->getIncrementalErrorOutput()) + Str::of($errorOutput) ->explode("\n") ->filter() ->each(function ($output) { diff --git a/src/Commands/StartSwooleCommand.php b/src/Commands/StartSwooleCommand.php index 6c52ac555..6d53ad2b0 100644 --- a/src/Commands/StartSwooleCommand.php +++ b/src/Commands/StartSwooleCommand.php @@ -170,7 +170,9 @@ protected function taskWorkerCount(SwooleExtension $extension) */ protected function writeServerOutput($server) { - Str::of($server->getIncrementalOutput()) + [$output, $errorOutput] = $this->getServerOutput($server); + + Str::of($output) ->explode("\n") ->filter() ->each(fn ($output) => is_array($stream = json_decode($output, true)) @@ -178,7 +180,7 @@ protected function writeServerOutput($server) : $this->info($output) ); - Str::of($server->getIncrementalErrorOutput()) + Str::of($errorOutput) ->explode("\n") ->filter() ->groupBy(fn ($output) => $output)