Re: Unknown entity changing ini settings in Unknown file on line 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 26/04/2019 15:55, Jānis Elmeris wrote:
Hello!

How do I go about debugging and eventually solving this error message
I keep getting on my site?

PHP Warning: Unknown: Headers already sent. You cannot change the session module's ini settings at this time in Unknown on line 0
I cannot reliably reproduce it, but it happens several times a day on
the production environment, and it has also happened on my local
environment (but far less frequently).

The related access_log entries do not help (at least not
straightforwardly) – I do not see anything apparently common to all
the suspicious / related requests.
I've checked for ini and session related functions used in the code,
and I couldn't see a problem there. Besides, if there was an explicit
ini_set, header, session_start or similar problem in the code, the
error message would be more generous with the trace than just "Unknown
in Unknown on line 0", right?

I've tried setting "output_buffering = On", which may be reducing the
amount of warnings (or it may be a coincidence), but they are still
appearing.

The Nginx and PHP configuration syntax seems to be all right, although
we may be missing something there.

PHP version is 7.2.17
We're using Nginx and PHP-FPM.

The modules are loaded by the /etc/php/7.2/mods-available convention,
and there seem to be no modules being loaded more than once.
We also have XDebug module enabled at the moment, but the warning
appeared also when it was disabled.

Any help would be much appreciated.
Janis


Hi Janis,

There are several causes, but almost all are caused by some form of output before the first session_start() or before the first setcookie().


How to debug this:

1) Search your entire code for a php end-tag. e.g.   ?> Check if there is a space or a line break after this end tag and if there is, delete it. This isn't too relevant in wordpress templates.

2) Also do the same for php start tags. Search for <?php and check if there are any spaces before the tag and delete them.

3) If you manage to catch a page with the error, look at the generated source-code in your browser. Don't use the web inspector (use CTRL-U to see the real source-code). Check if there is junk before the <!DOCTYPE. Any stray php output usually appears before this declaration.

4) Try as many states of your application as you can to try and home-in on the error. i.e. if you're using an online shop, test while logged in, while logged out, with an empty shopping basket, with an empty shopping basket to try and reproduce the error.

5) It could be ANOTHER error message causing the error. i.e. wordpress throws an error for some reason saying e.g.: "Notice: bla bla." and THIS is then interpreted as output, meaning the Headers already sent is an error which only occurs in the event of another error. If you can, check your PHP error logs to see if you can see any previous errors which could be causing this. Notices and Warnings are usual candidates.

6) Reconfigure PHP to only log errors to a file- see if this fixes the problem.

7) Register your own error handler (see php.net on how to do this) and log the current URL when the specific header error occurs.


Hope you get it fixed.


Regards

Dave



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux