note 96418 added to function.debug-backtrace

From: Date: Fri, 26 Feb 2010 06:02:15 +0000
Subject: note 96418 added to function.debug-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-166388@lists.php.net to get a copy of this message
Everybody seems to have their favorite use. I substitute this function for die(). It gives a message to the user and emails me a PrettyPrint of what went wrong. $info is set by me, and it does a special check in the database object. <? // var_format function var_format($v) // pretty-print var_export { return (str_replace(array("\n"," ","array"), array("<br>","&nbsp;","&nbsp;<i>array</i>"), var_export($v,true))."<br>"); } function myDie($info) { $mysqlerr=strpos($info,"ERROR=You have an error in your SQL syntax"); if($mysqlerr>0)$info=substr($info,0,$mysqlerr)." mySql format error"; $out="<br>MSG='$info'<br>".var_format($_REQUEST)."<br>"; $bt=debug_backtrace(); $sp=0; $trace=""; foreach($bt as $k=>$v) { extract($v); $file=substr($file,1+strrpos($file,"/")); if($file=="db.php")continue; // the db object $trace.=str_repeat("&nbsp;",++$sp); //spaces(++$sp); $trace.="file=$file, line=$line, function=$function<br>"; } $out.="<br>".backTrace(); if(substr($info,0,4)=="XXX ") // special errrors when db is inaccessible { $out=str_replace("<br>","\n",$out); $out=str_replace("&nbsp;"," ",$out); mail("me@somewhere.com","Database Execution Error for user ".$REMOTE_ADDR,"$out"); exit("Database Access Error. Please try again later."); } mail("me@somewhere.com",'Error Monitor','Execution Error',$out); exit("DANG! An execution error in the program has been sent to the webmaster. If you don't get an email from him soon, please call him."); } ?> This produces an output like this file=badmode.php, line=5, function=backTrace file=login.php, line=209, function=require file=midScreen.php, line=264, function=require file=masterindex.php, line=161, function=require file=production2.php, line=121, function=require file=index.php, line=16, function=require ---- Server IP: 64.71.164.2 Probable Submitter: 75.168.118.179 ---- Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php Edit -- https://master.php.net/note/edit/96418 Del: integrated -- https://master.php.net/note/delete/96418/integrated Del: useless -- https://master.php.net/note/delete/96418/useless Del: bad code -- https://master.php.net/note/delete/96418/bad+code Del: spam -- https://master.php.net/note/delete/96418/spam Del: non-english -- https://master.php.net/note/delete/96418/non-english Del: in docs -- https://master.php.net/note/delete/96418/in+docs Del: other reasons-- https://master.php.net/note/delete/96418 Reject -- https://master.php.net/note/reject/96418 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166388) next »