"Cannot modify header information" error encountered while streaming #9357
-
Livewire versionv3.6.3 Laravel versionv12.16.0 Which PHP version are you using?PHP 8.2 What is the problem?I'm trying to use Livewire streams in my Laravel app but I keep getting the following error from the Laravel logs, and also, on the front end, I'm getting a
At first I thought it was a Livewire bug, but after checking I found that Livewire streaming worked fine in Laravel framework v10.48.29 without triggering any errors. However, Livewire streaming have issue in both v11.0.0 and the latest v12.16.0. And I installed Livewire with the same version between v10 and v12. By the way, I'm using Herd. Code snippetsThe codes is CountDown component that copied from https://livewire.laravel.com/docs/wire-stream. <?php
namespace App\Livewire;
use Livewire\Component;
class CountDown extends Component
{
public $start = 3;
public function begin()
{
while ($this->start >= 0) {
// Stream the current count to the browser...
$this->stream(
to: 'count',
content: $this->start,
replace: true,
);
// Pause for 1 second between numbers...
sleep(1);
// Decrement the counter...
$this->start = $this->start - 1;
};
}
public function render()
{
return view('livewire.count-down');
}
}<div>
<button wire:click="begin">Start count-down</button>
<h1>Count: <span wire:stream="count">{{ $start }}</span></h1>
</div>Unfortunately, wirebox is using Laravel 10 version which streaming is works fine. You could check out my repo below. I installed a fresh new Laravel app with just Livewire installed to make sure nothing else was affecting the test results.
laravel/laravel => v10.3.3 laravel/laravel => v11.6.1 laravel/laravel => v12.0.9 Wirebox URLHow do you expect it to work?This should not give any errors, as streaming worked fine in Laravel v10. Please confirm (incomplete submissions will not be addressed)
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
|
After digging deeper into the code, I found this PR symfony/symfony#60377 that triggered above issue. |
Beta Was this translation helpful? Give feedback.
-
|
@sarukomine, @david371571 - just ran into this as well. Thanks for the work in diagnosing this! |
Beta Was this translation helpful? Give feedback.
-
|
According to symphony this should be fixed in Livewire symfony/symfony#60603 @joshhanley I think it's worth having a look if possible. |
Beta Was this translation helpful? Give feedback.
-
|
Another workaround is to suppress the error so that packages can be up to date. Add in public function boot(): void
{
set_error_handler(function ($errno, $errstr, $errfile) {
if (str_contains($errstr, 'Cannot modify header information - headers already sent') &&
(str_contains($errfile, 'livewire/src/Features/SupportStreaming/SupportStreaming.php'))) {
return true;
}
return false;
}, E_ERROR);
} |
Beta Was this translation helpful? Give feedback.

After digging deeper into the code, I found this PR symfony/symfony#60377 that triggered above issue.