Skip to content

Commit 873cdba

Browse files
authored
Only call the ob_flush function if there is active buffer (#55141)
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.
1 parent 1e1ed42 commit 873cdba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Illuminate/Routing/ResponseFactory.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ public function eventStream(Closure $callback, array $headers = [], StreamedEven
150150
echo 'data: '.$message;
151151
echo "\n\n";
152152

153-
ob_flush();
153+
if (ob_get_level() > 0) {
154+
ob_flush();
155+
}
156+
154157
flush();
155158
}
156159

@@ -166,7 +169,10 @@ public function eventStream(Closure $callback, array $headers = [], StreamedEven
166169
echo 'data: '.$endStreamWith;
167170
echo "\n\n";
168171

169-
ob_flush();
172+
if (ob_get_level() > 0) {
173+
ob_flush();
174+
}
175+
170176
flush();
171177
}
172178
}, 200, array_merge($headers, [

0 commit comments

Comments
 (0)