From e18d965ff759c51f9fd37fbf86c1ca725788d789 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sat, 22 Mar 2025 23:31:39 -0300 Subject: [PATCH] Only call the ob_flush function if there is active buffer When ob_flush() is called without first calling ob_start(), it fails saying there's no active buffer. To avoid this issue, we must check the buffer level before flushing it. --- src/Illuminate/Routing/ResponseFactory.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Routing/ResponseFactory.php b/src/Illuminate/Routing/ResponseFactory.php index a85b264daaeb..4a767e39482f 100644 --- a/src/Illuminate/Routing/ResponseFactory.php +++ b/src/Illuminate/Routing/ResponseFactory.php @@ -150,7 +150,10 @@ public function eventStream(Closure $callback, array $headers = [], StreamedEven echo 'data: '.$message; echo "\n\n"; - ob_flush(); + if (ob_get_level() > 0) { + ob_flush(); + } + flush(); } @@ -166,7 +169,10 @@ public function eventStream(Closure $callback, array $headers = [], StreamedEven echo 'data: '.$endStreamWith; echo "\n\n"; - ob_flush(); + if (ob_get_level() > 0) { + ob_flush(); + } + flush(); } }, 200, array_merge($headers, [