sunwukung Posted October 21, 2009 Share Posted October 21, 2009 Hi, I've been trying to write an error handling class that I can use on sites, that will email me in the event of an error. Problem is, when I profile the application, it's choking on the error_log function. Here's my code (omitting the class: class ErrorHandler { private static $instance; private static $mail; private function __clone(){} private function __construct() { error_reporting( E_ALL | E_STRICT ); if(!defined('ENV')){ if($_SERVER['SERVER_ADDR']=='127.0.0.1' || $_SERVER['SERVER_NAME']=='localhost') { #echo"local environment<br>"; DEFINE('ENV','LOCAL'); ini_set('display_errors', 1); } else { #echo"live environment"; DEFINE('ENV','LIVE'); ini_set('display_errors', 0); } } } public function setErrorConfig($error_level,$mail='',$mode='production') { error_reporting($error_level); switch($mode) { case 'development': ini_set('display_errors', '1'); break; case 'production': ini_set('display_errors', '0'); if($mail != ''){ self::$mail = $mail; set_error_handler(array('ErrorHandler', 'handleError')); } break; default: ini_set('display_errors', '0'); error_reporting( E_ERROR ); break; } } public function handleError($e_num,$e_msg,$e_file,$e_line,$e_vars) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: DC_Research Site' . "\r\n"; $msg = ''; $msg .= '<html><head></head><body>'; $msg .= '<STYLE>h2{font-family:verdana;}</STYLE>'; $msg .= '<h2>Error Description:</h2>'; $msg .= '<h2>Script:</h2><p>'.$e_file.'</p>'; $msg .= '<h2>Line:</h2><p>'.$e_line.'</p>'; $msg .= '<h2>Message:</h2><p>'.$e_msg.'</p>'; $msg .= '<h2>Variables:</h2><p>'.$e_vars.'</p>'; $msg .= '</html></body>'; #mail(self::$mail,'Error Report',$msg,$headers); error_log($msg,1,self::$mail,$headers); } } Can you help me figure out what's killing it? Quote Link to comment https://forums.phpfreaks.com/topic/178453-php-custom-error-logging-performance-issues/ Share on other sites More sharing options...
trq Posted October 21, 2009 Share Posted October 21, 2009 I'm not sure how this class is at all useful considering its construct is private yet it contains no static methods. You cannot instantiate this class into an object. Quote Link to comment https://forums.phpfreaks.com/topic/178453-php-custom-error-logging-performance-issues/#findComment-941043 Share on other sites More sharing options...
sunwukung Posted October 21, 2009 Author Share Posted October 21, 2009 Sorry - I should add that I've omitted this part of the code for the sake of brevity: public static function getInstance(){ if( !isset( self::$instance ) ){ self::$instance = new self(); } return self::$instance; } Which allows you to access it's methods. Quote Link to comment https://forums.phpfreaks.com/topic/178453-php-custom-error-logging-performance-issues/#findComment-941066 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.