3

Is it possible to configure php.ini to store errors in MySQL database rather than plain error-log?

The only option that I see is using php.ini to append file containing custom error handling function to every PHP script. Though, this doesn't sound efficient.

Gajus
  • 69,002
  • 70
  • 275
  • 438
  • 3
    possible duplicate of [Outputting all PHP errors to database not error_log](http://stackoverflow.com/questions/2911094/outputting-all-php-errors-to-database-not-error-log) – Frankie Jan 06 '12 at 16:54
  • Be warned that if you output errors to a mysql database and a user encounters an erronous page they could potentially flood your database with as much data as they like. – George Reith Jan 06 '12 at 16:58
  • @Frankie, it isn't duplicate since my question is asking for an efficient (cross-system not per script) way to output error log to database, rather than using custom errors handler within script it self. – Gajus Jan 06 '12 at 17:01

2 Answers2

1

This is more of a server level question, if you don't like the answer that Frankie provided in his comment. Without using set_error_handler there is no way (in PHP) to output all errors to a log file instead of the log.

If you are using Apache, you can do the following:

CustomLog "|/path/to/custom_log_script.php [OPTIONS]"

(note the pipe)

That will allow you to use a custom error log handler to control what does and doesn't wind up in the log files.

Jonathan Rich
  • 1,740
  • 10
  • 11
-1

You can set a cron job to execute a php script read the error log file for new errors and store them in the database. The error log table won't be real time though but I think it shouldn't be too big a problem.

Freeman
  • 1,201
  • 1
  • 11
  • 20
  • That's similar to what I am doing now. Though, I am looking for a way to make the error log file completely redundant. I bet there should be PHP extension or something, though, I haven't found anything alike yet. – Gajus Jan 06 '12 at 17:03