sKunKbad Posted May 2, 2011 Share Posted May 2, 2011 I've made a custom error handler, but it doesn't seem to work the same way on the dev and prod environments. Dev is windows/xampp, and prod is a standard LAMP install. Sometimes on prod I get a blank white screen and dev shows no errors. If I remove the error handler, everything goes back to normal. Just wondering if anyone sees something wrong here: <?php function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // email address to email errors to on the production environment $email_address = 'myemailaddress@gmail.com'; switch ($e_number) { case E_USER_ERROR: $error_type = 'E_USER_ERROR'; break; case E_USER_WARNING: $error_type = 'E_USER_WARNING'; break; case E_USER_NOTICE: $error_type = 'E_USER_NOTICE'; break; case E_WARNING: $error_type = 'E_WARNING'; break; case E_NOTICE: $error_type = 'E_NOTICE'; break; case E_STRICT: $error_type = 'E_STRICT'; break; default: $error_type = 'UNKNOWN ERROR TYPE'; break; } $message = '<hr />PHP ' . $error_type . ' #' . $e_number . ' - Date/Time: ' . date('n/j/Y H:i:s') . "\n" . '<br />File: <b>' . $e_file . "</b>\n" . '<br />Line: <b>' . $e_line . "</b>\n" . '<br /><b>' . $e_message . '</b><hr />'; // Output for development environment if (stristr($_SERVER['HTTP_HOST'], 'localhost' )) { echo $message; } // Email for production environment else { error_log($message, 1, $email_address ); if ( $e_number != E_NOTICE && $e_number < E_STRICT) { die('A system error occurred. We apologize for the inconvenience.'); } } // Don't execute PHP internal error handler return true; } function my_error_handling() { set_error_handler('my_error_handler', E_ALL); } Quote Link to comment https://forums.phpfreaks.com/topic/235367-error-handler-doesnt-work-the-same-on-dev-prod-environments/ Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 As you have set_error_handler('my_error_handler', E_ALL); within your my_error_handling() function make sure you are calling that function in order for the error handler to work. Also in order for errors to be displayed you need to enable display_errors either within your script using ini_set or within your PHP configuration file (php.ini). Also PHP will also log the errors within your servers error logs too. You can configure PHP to log errors to a dedicated file within the php.ini. You may be able set it with ini_se too. Quote Link to comment https://forums.phpfreaks.com/topic/235367-error-handler-doesnt-work-the-same-on-dev-prod-environments/#findComment-1209520 Share on other sites More sharing options...
sKunKbad Posted May 2, 2011 Author Share Posted May 2, 2011 Yes, the function is for sure being called. I'll need to check display_errors. What is odd is that most errors are being sent to me via email, which is a function of the custom error handler. There are just some instances where I'm getting a blank white screen, and removing the custom error handler seems to make that go away. Quote Link to comment https://forums.phpfreaks.com/topic/235367-error-handler-doesnt-work-the-same-on-dev-prod-environments/#findComment-1209547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.