Why are PHP errors printed twice?

前端 未结 2 1199
独厮守ぢ
独厮守ぢ 2021-01-31 03:15

Summary

Amazingly I could find nothing about this on Google or SO. When I throw an exception in PHP it appears in my console twice, complete with error message and sta

相关标签:
2条回答
  • 2021-01-31 03:58

    Like written in the answer of Linus Kleen the reason for the double messages is that the display_errors go to stdout. I found out that since php 5.2.4 this even happens when display_errors is set to 1 or "on".

    To restore the normal behavoir it is the best way to define file where logged errors should be stored e.g. add this:

    error_log = 'd:/logs/php_error.log'
    

    to your php.ini. When the file for error_log is defined, you get only one message to stdout what you would need for testing. And for production state you can set display_errors to 0.

    0 讨论(0)
  • 2021-01-31 04:10

    Got it reproduced. The first error message is a result of the log_errors setting and goes to STDERR.

    The second is a result of display_errors and goes to STDOUT.

    Both settings can be altered during runtime. So in order to "ask PHP nicely", this suffices:

    ini_set('log_errors', 1);
    ini_set('display_errors', 0);
    
    0 讨论(0)
提交回复
热议问题