Is there a way to email / log php fatal errors happening in the project based on Yii framework?
For example it is possible to configure Yii to email "undefined variable" errors but fatal ones can only be monitored by a separate, non integrated into framework code which is not ideal.
In php it is possible to intercept fatal errors using
register_shutdown_function()
function.Firstly, lets add "early" fatal and parse error handler. It should go into index.php. The purpose of this code is to catch those errors that could happened before controller has been initiated. As we are catching errors which could occur during application initiation it is better to use simple php without reliance on any external libs:
At this stage we are still not using Yii error handler nor logging. To start we need to register another shutdown function which is part of our base controller and can use standard error handling AND error logging provided by Yii framework (credits for the idea and bigger part of the code goes to vitalets @ http://habrahabr.ru/post/136138/)
Note that this function will notify about parse errors as long as they are not parse errors in the actual controller files but in external files like models, helpers, views. If parse error is in controller early handler will deal with it.
Also this function allows to render a nicer error page rather then dumping fatal error text or showing a blank screen (if display_errors is off).