NYCPHP Meetup

NYPHP.org

[nycphp-talk] New PHundamentals Article - Error Handling

Chris Shiflett shiflett at php.net
Mon Jul 19 17:27:02 EDT 2004


--- Jeff Siegel - PHundamentals <jeff.siegel at nyphp.org> wrote:
> A new PHundamentals article - "Error Handling" - has been posted.

I like much of what is written. However, I wouldn't consider enabling
show_errors to be a bad practice in development. This is argued as
follows:

"Even in development, errors dumped to the browser are bad because they
can become hidden in the HTML."

I typically advocate ugly, obvious errors in development and tasteful,
hidden errors in production. I've worked with many developers, and I've
never known someone to overlook an error due to some invalid (or
incomplete, due to the nature of the error) HTML.

My suggestions, as far as php.ini directives, go something like this:

Development:
error_reporting = E_ALL
log_errors = Off
display_errors = On

Production:
error_reporting = E_ALL
log_errors = On
display_errors = Off
error_log = "/tmp/php_errors.log"

All of these can be set anywhere (PHP_INI_ALL). The article states that
the error log goes to one of two places, and neither of these mention that
this can be set with the error_log directive. I prefer my PHP errors to be
in their own file, but this comes down to personal preference.

This is a pretty rudimentary approach, but it's a good "least you can do"
approach that doesn't require much effort. Set a few PHP directives, and
you're off to the races.

There are different methods of dealing with error notification, and I'm
not an expert in this area, but I do think you would want your approach to
be out-of-band with your PHP code, since you don't want a million emails
describing the same problem. :-) I've been known to do something as write
a shell script that checks to see whether anything new is in the log, and
if so, email the difference (so, the backup is replaced each time the
script is run). Put this in your crontab, and run as often as you think is
appropriate.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
     Coming Fall 2004
HTTP Developer's Handbook - Sams
     http://httphandbook.org/
PHP Community Site
     http://phpcommunity.org/



More information about the talk mailing list