0

Are there any reports/logs saying all PHP and MySQL errors that occured on server? With date, time, some user info (browser, IP), and count of that error happened if possible.

In addition every time my mysql_query fails die message is pulled from included file:

$error_message[0] = 'Error no. 0!';
$error_message[1] = 'Error no. 1!';
$error_message[2] = 'Error no. 2!';

Is there a way to monitor which message and when was displayed?

3
  • why not implement some logging facility by yourself? Commented Sep 11, 2012 at 13:38
  • 2
    In general, using mysql_query() || die() should only be for initial development. Once you've got it working, you should instead raise an typed exception, and try to plan for, and catch, pretty much everything. Commented Sep 11, 2012 at 13:48
  • Thats a good point there @halfer Commented Sep 11, 2012 at 13:51

5 Answers 5

1

Yes, there are error logs for both: httpd (or apache) and mysqld.

You find them in:

/var/log/httpd/error_log
/var/log/mysqld.log

(these path could be a little different on your sever depends on configuration files, eg. you can specify mysql error log file location passing --log-error=XXX option to mysqld)

Sign up to request clarification or add additional context in comments.

2 Comments

Cool! What about 2nd part of my question?
What do you mean by "monitor message and display it" ? Eg. you can send an email when some error occurs (here is link: oksoft.blogspot.com/2012/08/monitoring-mysql-error-log.html). If you meant something else please let me know
1

You can do it by sticking to exceptions instead of "die()" calls, and by catching them, then logging.

Good solution for that is eg. Sentry - it saves information in the way you require (time of occurrence, details, number of occurences, logger/category, level etc.).

Comments

0

Look in /var/logs/apache/ or /var/logs/httpd/ if it's a Linux / UNIX server.

Comments

0

"Is there a way to monitor which message and when was displayed?"

This is not about the main question, however if you're worried about exposed error messages, you can simply disable showing errors in PHP, which actually means you would not have MySQL errors showing to the visitors also (You're working on MySQL via PHP, if you're talking about a web application)

That might help! :)

1 Comment

Its not the case, I want to monitor how often they was posted, in situation that I have no access to logs
0

Do you think try, catch would works then? you just need to use it everywhere in order to catch all the possible errors.

You may also make your own MySQL adapter class and then wrap the original functions inside the try, catch block. That would make it easier if you could apply that on your code, but for PHP errors, still need to cover fatal-error-possible parts, e.g. working on file system, with try, catch blocks manually.

When you're gonna log them on the database or file system, obviously you can log the date and time also.

PHP manual/Exceptions

Note: you may consider the overhead also! you can benchmark to see how much your code would be slower after using try, catch blocks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.