CHAPTER 7 – Custom Error Handlers

Instead of having PHP print or log the error message, you can register a function that is called for each error. This way, you can log errors to a database or even send an email alert to a pager or to mobile phone. The following example logs all notices to /var/log/httpd/my-php-errors.log and converts other errors to PEAR errors: <?php function my_error_handler($errno, $errstr, $file, $line) { if ($errno == E_NOTICE || $errno == E_USER_NOTICE) { error_log("$file:$line $errtype: $errmsgn", 3, "/var/log/httpd/my-php-errors.log"); return; } PEAR::raiseError($errstr); } ?>

Post Comment
Login to post comments