UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 20th March 2010, 03:56 PM   #1 (permalink)
MalcolmCowen
Registered User
 
Join Date: Jun 2006
Location: Manchester, England, UK
Posts: 30
using set_error_handler

I do quite a lot of development on clients' hostings, and I've got my own error handling routine which I use in development to speed up debugging.
(reports errors direct to my webpage, insread of going to error_log and downloading that!)

But when I try it on UH hosting it doesn't pick up all errors.

It will catch and report errors like

Example 1 - misspelt pathname
include("../misspeltincludes/Functions.php");
is reported as
2010-03-20 15:44:16 (GMT) 2 Warning include() [function.include]: Failed opening '../misspeltincludes/Functions.php' for inclusion (include_path='.:/php/includes:/usr/share/php:/usr/share/pear') /home/ebook/public_html/Stories/Summary.php 4

Example 2 - invalid command
jjj;
is reported as
2010-03-20 15:44:16 (GMT) 8 Notice1 Use of undefined constant jjj - assumed 'jjj' /home/ebook/public_html/Stories/Summary.php 23

But when I make a mistake such as a missed out semicolon
$Dot = strrpos($Story,'.')
$Story = substr($Story,0,$Dot);

Then the error handler is not called at all, and I have to go to error_log.

My clients' hostings (such as Fast Hosts) do report this kind of error, which is after all one of the most common ones.

Any reason why UH error handling works differently?


Here's my error handler



// user defined error handling function
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {
// timestamp for the error entry
$dt = date("Y-m-d H:i:s (T)");

// define an assoc array of error string
// in reality the only entries we should
// consider are 2,8,256,512 and 1024
$errortype = array (
1 => "Error",
2 => "Warning",
4 => "Parsing Error",
8 => "Notice",
16 => "Core Error",
32 => "Core Warning",
64 => "Compile Error",
128 => "Compile Warning",
256 => "User Error",
512 => "User Warning",
1024=> "User Notice" ,
2048=> "Notice",
4096=> "Recoverable Error"
);
// set of errors for which a var trace will be saved
$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

$err = "<errorentry>\n";
$err .= "\t<datetime>".$dt."</datetime>\n";
$err .= "\t<errornum>".$errno."</errnumber>\n";
$err .= "\t<errortype>".$errortype[$errno]."</errortype>\n";
$err .= "\t<errormsg>".$errmsg."</errormsg>\n";
$err .= "\t<scriptname>".$filename."</scriptname>\n";
$err .= "\t<scriptlinenum>".$linenum."</scriptlinenum><br/>\n";

if (in_array($errno, $user_errors))
$err .= "\t<vartrace>".wddx_serialize_value($vars,"Variabl es")."</vartrace>\n";
$err .= "</errorentry>\n\n";

if ( ($errno <> 8) & ($errno <> 2048) ) echo $err; // for testing

// save to the error log, and e-mail me if there is a critical user error
//error_log($err, 3, "/usr/local/php4/error.log");
//if ($errno == E_USER_ERROR)
// mail("phpdev@mydomain.com","Critical User Error",$err);
//}
}


/* We will do our own error handling*/
error_reporting(E_ALL);
$old_error_handler = set_error_handler("userErrorHandler");
__________________
Malcolm
MalcolmCowen is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 06:38 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  SEO by vBSEO 3.0.0
Copyright © 1998-2009 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309