2

I'd like for PHP to still send it's minor and fatal errors to the error log but not display it to the user. I thought at first I could use error_reporting(0); to suppress all error messages, period, but that's not really ideal. I know I could also put everything inside a try-catch but that's not really ideal either. Is there anything more automatic for regular errors like there are for fatal errors (e.g. register_shutdown_function())?

Speaking of fatal errors, I tried catching them using register_shutdown_function() as suggested in this SO answer. When I did it this way the fatal error was caught but error_get_last(); is always empty. I also tried making use of debug_backtrace(); to catch the error message. It does contain the info I want about fatal errors but it appears to have the undesired side effect of actually printing that info out to the user, the very situation I am trying to avoid.

Are there any other ways to do what I'm trying to do here and/or ways I can do this (log the error messages to the console but not to the user) using the methods I have described above? Thank you.

Community
  • 1
  • 1
keybored
  • 5,194
  • 13
  • 45
  • 70
  • Please see the manual for the settings that exist: http://php.net/manual/en/errorfunc.configuration.php – hakre Mar 15 '12 at 16:55

1 Answers1

4

Set display_errors=0 and log_errors=1 in php.ini.

This should be the default for any production server.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Tyler Eaves
  • 12,879
  • 1
  • 32
  • 39
  • Oh geez, you're right, I'll have to talk to the admin that set up that app server and ask them why php.ini isn't set up that way on production. Thank you! – keybored Mar 15 '12 at 17:13