Best Practices for Live Website Error Management
Asked Answered
T

5

6

I am just about to launch a fairly large website for the first time. I have turned off all error messages in my php.ini and error messages are now logged to an "error_log" file on my server.

My question is, now that the errors are logged to a file, what are the best ways that web developers keep on top of seeing when/where errors occur on the website?

At the moment, it seems like the best way would be to constantly check the error_log file everyday, however this doesn't seem like the most efficient solution. Ideally I would receive an email everytime an error occurs (with the error message). Any advice on how I can keep on top of errors would be greatly appreciated!

Extra Info
Running on Shared Server (HostMonster)
Website Authored in PHP

Translucid answered 16/10, 2009 at 23:56 Comment(0)
W
5

There are two main functions in PHP that help catching errors and exceptions. I suggest that you take a look at them :

In our company, we handle all errors that occurs on our websites with those functions, defining our own errors and exceptions handling methods.

When an error occurs, an email is sent to the developers team.

Weichsel answered 17/10, 2009 at 0:27 Comment(2)
Thanks MaxiWheat. If I'm to go this route, then on every PHP script I'll need to include my custom error handler, right?Translucid
Yes, that custom handler needs to be included in every script. If you don't want bothering, you can use it in an auto prepend file, more info here : php.net/manual/en/ini.core.phpWeichsel
R
2

The place I previously worked at used a custom extension to handle error logging. It basically INSERT DELAY the errors into a DB with some extra information. Then, a separate admin tool was written to be able to easily search, browse, sort and manually prune the log table.

I recommend that you don't write a custom extension, but that you use the set_error_handler method and just write to a DB instead. If the DB is unavailable, then write to a file as a backup. It'll be worlds easier than dealing with a huge file and a one-off format.

If you want, you can also email yourself hourly summaries, but I don't suggest you send anything more than that or you'll be hating yourself.

Remotion answered 17/10, 2009 at 0:5 Comment(2)
one point to note here is that set_error_handler() doesn't handle all error types (from php.net): The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.Wrought
Wanting error reporting about the broken error reporting mechanism is kind of paradoxical, isn't it?Remotion
A
0

You can email yourself on errors, if there was no email in last N hours.

Abduce answered 16/10, 2009 at 23:59 Comment(0)
N
0

If you don't expect many errors, a "private" RSS/ATOM feed might work well... whereby you don't need to worry if you don't get anything... but if you start getting "updates" you know there are issues.

Nussbaum answered 17/10, 2009 at 0:11 Comment(0)
M
0

I don't know how Hostmonster handles log rotation, but generally you want to monitor the size of your error_log file. If the size jumps suddenly, there's definitely something you need to check up on so you'ld want to get an email telling you that the logfile size jumped unexpectedly.

Other than that, you can combine the error logs at the end of the week and email them to yourself and debug on the weekend. If an error is only happening a few times a week it's probably not too serious of an issue.

Miscarriage answered 17/10, 2009 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.