views:

144

answers:

4

Hi there

I'm developing a web-application using PHP which is on tests by some of my friends. What approach do you recommend me to use in order to know what warnings are they getting but without displaying them using ini_set('display_errors', 1); ?

Also, the application will run in a intranet in which I'll not have access remotely.

I was thinking to send daily emails with some information to me, but i don't know which are important facts to be saved. Do you have a article/sample for me? Do you have a better advice for me?

+5  A: 
  • You can log the errors without displaying them.

For example you can do something like:

error_reporting(E_ALL | E_STRICT); //For PHP 6 E_STRICT become part of E_ALL
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
ini_set('error_log', $_SERVER['DOCUMENT_ROOT'] . '/php.log');

You can also edit PHP.ini or do it with an .htaccess (if on Apache).

  • If you can't access this log remotely you can make a small PHP application that will send you the log via email.

You can use PHP mail() but a library like PHPMailer will speed things up (and will be easier to use).

  • Have a CRON job (or something equivalent) fire the email every day (or week or else).
AlexV
A: 

I think that it's the only possibility.

If you could connect there you could see apache log.

But otherwise. I'm sorry.

oneat
+2  A: 

Write an error handler and use set_error_handler to make sure it's called instead of the default one. In that handler, you can do whatever you think is best for your purpose.

If you want to do a daily e-mail, you would save the data to a database or file, and make a cronjob run once a day to send the e-mail with the latest data. I would probably prefer to just save to a logging table in a database, which I can then view via some interface when relevant.

That's not going to catch EVERYTHING, though - all E_WARNING will be caught, but not all other types will be. For example, parse errors can't be caught this way, and if you might want to handle exceptions as well, you should use set_exception_handler.

Michael Madsen
A: 

My best advice is to read up on PHP's set_error_handler function. It lets you determine exactly what happens whenever some error occurs -- whether you email it, log it, or whatever you want to do.

Now, there are numerous great articles on logging errors in PHP instead of displaying them to the end user. Some random examples, which I found with a 30 second Google search: http://davidwalsh.name/custom-error-handling-php http://www.electrictoolbox.com/log-php-errors-log-errors-error-log/ http://www.w3schools.com/php/php_error.asp

There are many ways to handle errors in PHP. Besides the aforementioned, you could rely on the default PHP error logs (by default, PHP use's Apache's error logs, i.e. /var/log/httpd/error_log). However you can modify your php.ini to send the messages to any file you like. You can check that file daily to see what errors occur.

You could also setup a CRONTAB script to read in that file once per day and email it to you, then clear it out.

Again, I'd suggest set_error_handler as a more flexible option.

Brian Lacy