PHP Error Logging

Whilst having error messages output to the browser can be handy to developers, production servers should NEVER have PHP error messages sent to the browser.

  • It looks ugly
  • It gives the user the impression that the site is buggy/broken
  • It can give away important information about the workings of your site/system

The third reason is of course by far the most important.

Edit php.ini (typically /usr/local/lib/php.ini) and use:

error_reporting = E_ALL
display_errors = Off
log_errors = On
error_log = /usr/local/apache/logs/php_errors

(change to suit, obviously)

logging with error_log()

You can add your own entries to the error log with the error_log() function - by default, you can supply one parameter (the log message) which will be sent to the logfile (or syslog) which PHP is configured to log to (with the file + line number).

Alternatively there are other options for sending it to a specific file or via email - see the PHP docs for more info.

raising errors with trigger_error()

You can raise user-defined errors with trigger_error().

 
php/errorlog.txt · Last modified: 2010/02/26 10:45 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki