Atb.: Unknown entity changing ini settings in Unknown file on line 0

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

 



Thank you for the comprehensive list of ideas!

I'm currently not actively investigating this issue any more. But I'll let you know if I find the reason out in the end.

---

1) 2) Searching PHP open or close tags is not easy. First of all, a quick search tells me there are 43777 open tags, for example. Secondly, PHP open/close tags may be used within code, which may or may not cause the "Headers already sent" based on how/when that code is executed.

And I don't think this is going to get me any results due to the reasons I've already described (the timing of the error, the lack of source in the error message, the inconsistency of the error occurrences). But it is something to keep in mind, of course. Who knows.

3) OK, I'll take a look at the source code if I catch one.

4) The error occurs inconsistently. I can open the same product many times, and once out of 20 times the error happens. I can add a product to the cart (AJAX call), and once out of 20 times the error may happen. It happens sometimes when I log in. It sometimes happens on background tasks (background, periodic AJAX calls by WP, when the user does not do anything, the page is just open), but mostly not.

5) There have been many cases when no other message in the error log precedes it (for >10 seconds).

6) The PHP is configured to output errors only to the error_log file. Or did you mean something else?

7) For the custom error handler to have an effect, it needs to be executed/attached before the error happens, however this error seems to happen before any PHP code is executed (I've concluded this based on using "auto_prepend_file"). But I've logged the URLs the error seems to happen at (for example, using the access log, but also using a common WP script that gets loaded in all cases (wp-load.php)). And the error seem to happen on different pages for different URLs (see 4).

Regards,
Janis



No: Dave Holloway <lists@xxxxxxxxxx>
Nosūtīts: svētdiena, 2022. gada 13. februāris 21:39
Kam: php-general@xxxxxxxxxxxxx <php-general@xxxxxxxxxxxxx>
Tēma: Re: Unknown entity changing ini settings in Unknown file on line 0
 

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