From 6749faa89a9faa6f21ba173c1736f6bbba72a8f8 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 2 Apr 2022 18:42:15 +0100 Subject: [PATCH] Fixed streamed outputs in more extreme scenarios Fixes hitting memory limits where downloaded file sizes are much greater than memory limit. Stopping and flushing output buffer seemed to stop limits causing issues when fpassthru is used. Tested with 24M memory limit and 734M file --- app/Http/Controllers/Controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index ae1f4e4ba..4c979c26a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -127,6 +127,7 @@ abstract class Controller extends BaseController protected function streamedDownloadResponse($stream, string $fileName): StreamedResponse { return response()->stream(function() use ($stream) { + ob_end_clean(); fpassthru($stream); fclose($stream); }, 200, [