Reputation: 2735
Background
On live environments you have to fix things from time to time. After you publish your code, some errors or glitches may slip through and go live on your page.
Users often do not report back on the errors so the page is broken until you discover it on your own.
Question
Is there a recommended way in PHP to detect something that is broken when there is a PHP error besides the PHP log?
For example, would you recommend to place a code that emails you if an error occurs on the page?
Thank you
Upvotes: 0
Views: 90
Reputation: 95121
I think you should start maximizing the use of Exception
http://php.net/manual/en/language.exceptions.php and creation of custom set_error_handler
http://php.net/manual/en/function.set-error-handler.php with this features you can begin to categories your error and diffident format for notification
Example
GreenException
Save to MongoDB log
BlueException
Send to Review
WhiteException
Send me a Mail
UnknownException
Send me a SMS
You should also try to make during development the following settings are turn on and never suppress any error
error_reporting(E_ALL);
ini_set('display_errors','On');
Develop your application in such a way where everything is validated and verified
Example (File Upload) or else throw Exception
Can I upload
File Was Updated
Is it a valid File
Does the destination folder exist
Is it writable
Copy File
Was File successfully copied
etc .....
This way you would minimize production errors
Last always ... do unit testing
.....
Upvotes: 1