views:

40

answers:

2

Hi,

I am using CakePHP in PHP development. I have set my debug mode to 0 in core.php file.

Configure::write('debug', 1);

This setting will not show any error on site. So the user/developer will not be able to see errors. Thant's why I want to make something that will send me an email with error title and error code like Warning message, notice(8): like error messages. So that if error occurs, it wouldn't be ignored.

Thanks.

A: 

If you get an email every time an error occurs, you will be flooded until the error is fixed which is probably not very efficient or productive.

You could write an error emailing system with throttle control, where as soon as each error is raised from CakePHP it is placed in a database (perhaps keyed on md5(errortext)) and emailed immediately to whoever is interested. Then, next time the exact same error is encountered, the system will see that it's already in the database (same md5) and not email it again.

Also, can't CakePHP be configured to log the errors to a log file? Then you can check that for errors, either manually or via something like logcheck, which will run in a frequent schedule, check the CakePHP logfile for specific errors, and email out a summary if any new ones are found.

Fanis
Yes Fanis, but it has become a requirement in some of the web applications. I have seen some websites having this feature.
lakum4stackof
If the web server is on linux I suggest you look into logcheck. I'm using that to email the dev team any new entries in the php error log shortly after they're logged there. You can have it monitor other logs as well, eg the CakePHP application log.
Fanis
A: 

I think you could achieve this goal by overriding PHP's default error handler. The relevant PHP manual page: http://php.net/manual/en/function.set-error-handler.php

Basically, you'd just define a function (and tell your script to call that function on an error). Your definition needs to appropriately return false or die() on an error (otherwise the script will continue to execute). However, in that function you would be able to make a call to send emails.

Note that if you're doing it within CakePHP you may need to pass the current object as a parameter, otherwise it's likely that error handler you define won't tie in nicely with the other cake object stuff.

Travis Leleu