I am in the middle of refining a rather large bit of code. Alot of it contains many general warnings and notices which do not affect the execution of the code (ie: undefined varilables, or array keys without qoutes).
I want to write a function which allows me to concentrate on the fatal errors first and then I will open it up to the less urgent warnings and notices. I found this code, but it emails every little warning notice and error.
http://net.tutsplus.com/tutorials/php/quick-tip-email-error-logs-to-yourself-with-php/
How can I modify this code so it only deals with things like:
- fatal syntax errors
- undefined functions
- failure to include files
set_error_handler
allows you to specify a user-defined error handling function for deciding what to do with certain (but only non-fatal) errors. You can then handle specific types of errors in any fashion you deem necessary, for example notifying a system administrator via email, or saving to a specific log file. See: PHP Doc for further details.With regards to your request you could the following approach:
As that error-handling does not work for Fatal Errors (Parse errors, undefined functions etc.), you need to tape this with
register_shutdown_function
as outlined in a related question:Init following function inside your php file.
fatal_error_structure
should be defined on some global location. likefunction.inc.php
. This will send an email to registered user.Alerternatively you can use (if you have shell access) a log watcher shell script. This allows to catch any error, including parse errors (which you cannot catch with register_shutdown_function).
This is imho more harmless because this is just a side process, and allows you to rely on other technology (shell script or whatever), in case errors happen because of php environment itself, you will still be notified.
Take a look at this
If you where to set your error reporting to something like
Then the hope would be that it would pick up the above problems.