简体   繁体   中英

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

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.

After looking and searching for a response finally I got one from a post here in StackOverflow, I am letting here the answer in case it's gonna help anyone.

I did a composer update and unfortunately, it was not solved, but at least did update my dependencies.

The issue was caused by malware. By installing htop on my container I could see that malware named:

  • /tmp/kinsing and
  • /tmp/kdevtmpfsi

were taking all my CPU.

This was due to the fact that my local server had the 9000 port open for my PHP docker container, I had then to kill, remove them, and of course secure in a better way my container.

What should you check?

  • Install htop
  • Run htop
  • Check if there are any suspicious activities
  • Clean and secure your container by avoiding by example to use open ports

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM