What's the best way to get errors from a production site in PHP?

For most production sites, you want to know when the error occurred as soon as possible. My question is how best to get this information.

It is usually best to receive errors in an email, as I will not sit around every day and watch the error logs until the error appears - that would not be possible since I have 20 or more production sites on different servers. These errors can be anything, including undefined variables, invalid data received, or query errors.

For the moment, I have followed the example of the PHP websites found here . This creates a text string along with an XML file, which is then sent by email. I modified this slightly to keep all errors until the end of the script and then send an email with the XML files attached. (I crashed a couple of mail servers sending over 500,000 emails due to a loop error.) Most of the time this works fine. (I also created an object to do all of the error handling.)

The problem arises when there is a large amount of data wddx_serialize_value()

for processes. And then if there are multiple errors, then it really ends up using most of the memory, most of the time more than the script is allowed to use.

Due to this, I added an append gzcompress()

to the XML file before storing it inside a variable. This helps, but if the amount of data is very large, it still runs out of memory. (In a recent case, he wanted to use about 2GB.)

I'm wondering what other solutions are out there for this or how did you change this to get it to work?

So, a few requirements:

  • it should be able to send me more than just an error message and shouldn't force me to log into the server to figure out what happened (so I can check when mobile and determine if it's urgent)
  • there should be a limit on the number of emails sent. Best of all 1.
  • it needs to log in to the file as normal

Edit: I need other information related to the error, not just the error line. I often find that it is nearly impossible to reproduce the error because it is caused by user input, which I am not aware of unless I get more information. I tried my best to put informative errors, but you never know how a user will use the system or what crap data they will insert. So I need more than just an error text / line.

Edit 2: Can't log errors to the database because for everyone I know there may be no database. You need something that's pretty much guaranteed. Also, sites are not all on the same server, and I often don't have cron access on the server (stupid hosting companies).

+1


source to share


4 answers


Instead of installing a custom error handler, I allow errors to access the error log as usual. I set up a cron that runs periodically and monitors changes in the error log - if it changes, it sends me an email with the changes. You can improve this process and analyze the changes according to your needs - for example, only submit bugs above a certain level (for example, E_WARNING and above).



+1


source


One approach might be to properly manage exceptions in your application, that is, control over what errors are logged.

Each raised exception logs error data to the database.



You can then code a small application to look up a database of errors, perhaps just one for all of your websites.

This way you avoid large unreadable log files because everything is indexed and searches are fast. When your database gets too big, you can prune your log tables using cron jobs.

+1


source


Anacron, a cron job that sends emails to the error log * and the error log file should be sufficient. The cron task can do all the processing needed to send the email.

0


source


One thing I've used in the past is epylog , which is a very flexible log monitoring application written in python. You can configure it to monitor your error logs and include errors (or parts of them) in the log summary that is sent to you by email.

I would lean towards storing more detailed error data in a flat file on the server and sending you an email to tell you to check the log. A cron task that keeps track of the error directory or files for changes and has a transfer rate limit would be a good way to minimize the impact on your running application.

0


source







All Articles