How to fix: "Failed to start the session because headers have already been sent by "php://input" at line 1."

  php, session, session-cookies, symfony, symfony4

I literally don’t know why this error suddenly appeared in my Symfony application version 4.4, without any changes suddenly the error started to be triggered:

Uncaught PHP Exception RuntimeException: "Failed to start the session because headers have already been sent by "php://input" at line 1." at /vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php line 152 {"exception":"[object] (RuntimeException(code: 0): Failed to start the session because headers have already been sent by "php://input" at line 1. at /vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:152)"}

The problem, when I try to go in a page that is using a session this error is appearing.

My env:

  • Docker PHP 7.4
  • Docker Apache 2

When it is appearing?

When I try to connect myself on a login page or another page that is using a session.

What did I try?

  • Checking if I have some spaces in a php file, this error started without even a change, the last changes before that error appears was 10 days ahead and not related to a session, the code was actually a two lines array_merge of two arrays.
  • Restarted my PHP container: when I restart it, it works until at some point it breaks without giving me more logs than the error above.
  • Changed the config for using another save_path for session as explained here: https://symfony.com/doc/current/session.html, knowing that it was not related I wanted to try to see if the location would change anything and if it was related to a memory.
  • Destroyed my php container and apache but the error still appears after some times and put down the entire platform by making anyone who tries to access it inaccessible.

The non permanent solution here is for me to restart my php container all the time I receive that error, but as you can see it is not a permanent solution.

On my dev env I cannot reproduce it.

If anyone has a solution for it please let me know I have been looking and trying to get answers during days now and even asked questions in Symfony slack support without any answer to help me.

Thanks a lot for the help.

Source: Symfony Questions

One Reply to “How to fix: "Failed to start the session because headers have already been sent by "php://input" at line 1."”

LEAVE A COMMENT