显示效果不错的PHP错误 异常处理类_第1页
显示效果不错的PHP错误 异常处理类_第2页
显示效果不错的PHP错误 异常处理类_第3页
显示效果不错的PHP错误 异常处理类_第4页
显示效果不错的PHP错误 异常处理类_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——显示效果不错的PHP错误异常处理类显示效果不错的PHP错误奇怪处理类

奋斗的双脚在踏碎自己的温床时,却开拓了一条创造之路。以下是我为大家探寻整理的`显示效果不错的PHP错误奇怪处理类,梦想能给大家带来扶助!更多精彩内容请实时关注我们我!

一、效果图:

二、实现代码

代码如下:

//自定义奇怪函数

set_exception_handlerhandle_exception;

//自定义错误函数

set_error_handlerhandle_error;

/**

*奇怪处理

*

*@parammixed$exception奇怪对象

*@author

*/

functionhandle_exception$exception

Error::exceptionError$exception;

/**

*错误处理

*

*@paramstring$errNo错误代码

*@paramstring$errStr错误信息

*@paramstring$errFile出错文件

*@paramstring$errLine出错行

*@author

*/

functionhandle_error$errNo,$errStr,$errFile,$errLine

if$errNo

Error::systemError$errStr,false,true,false;

/**

*系统错误处理

*

*@author

*/

classError

publicstaticfunctionsystemError$message,$show=true,$save=true,$halt=true

list$showTrace,$logTrace=self::debugBacktrace;

if$save

$messageSave=.$message.

PHP:.$logTrace;

self::writeErrorLog$messageSave;

if$show

self::showErrorsystem,

$message

,$showTrace,0;

if$halt

exit;

else

return$message;

/**

*代码执行过程回溯信息

*

*@static

*@accesspublic

*/

publicstaticfunctiondebugBacktrace

$skipFunc[]=Error-debugBacktrace;

$show=$log=;

$debugBacktrace=debug_backtrace;

ksort$debugBacktrace;

foreach$debugBacktraceas$k=$error

if!isset$error[file]

//利用反射API来获取方法/函数所在的文件和行数

try

ifisset$error[class]

$reflection=newReflectionMethod$error[class],$error[function];

else

$reflection=newReflectionFunction$error[function];

$error[file]=$reflection-getFileName;

$error[line]=$reflection-getStartLine;

catchException$e

continue;

$file=str_replaceSITE_PATH,,$error[file];

$func=isset$error[class]?$error[class]:;

$func.=isset$error[type]?$error[type]:;

$func.=isset$error[function]?$error[function]:;

ifin_array$func,$skipFunc

break;

$error[line]=sprintf%04d,$error[line];

$show.=

[Line:.$error[line].].$file..$func.

;

$log.=!empty$log?-:;

$log.=$file.:.$error[line];

returnarray$show,$log;

/**

*奇怪处理

*

*@static

*@accesspublic

*@parammixed$exception

*/

publicstaticfunctionexceptionError$exception

if$exceptioninstanceofDbException

$type=db;

else

$type=system;

if$type==db

$errorMsg=.$exception-getCode.;

$errorMsg.=self::sqlClear$exception-getMessage,$exception-getDbConfig;

if$exception-getSql

$errorMsg.=

;

$errorMsg.=self::sqlClear$exception-getSql,$exception-getDbConfig;

$errorMsg.=

;

else

$errorMsg=$exception-getMessage;

$trace=$exception-getTrace;

krsort$trace;

$trace[]=arrayfile=$exception-getFile,line=$exception-getLine,function=break;

$phpMsg=array;

foreach$traceas$error

if!empty$error[function]

$fun=;

if!empty$error[class]

$fun.=$error[class].$error[type];

$fun.=$error[function].;

if!empty$error[args]

$mark=;

foreach$error[args]as$arg

$fun.=$mark;

ifis_array$arg

$fun.=Array;

elseifis_bool$arg

$fun.=$arg?true:false;

elseifis_int$arg

$fun.=definedSITE_DEBUGSITE_DEBUG?$arg:%d;

elseifis_float$arg

$fun.=definedSITE_DEBUGSITE_DEBUG?$arg:%f;

else

$fun.=definedSITE_DEBUGSITE_DEBUG?.htmlspecialcharssubstrself::clear$arg,0,10.strlen$arg10?...:.:%s;

$mark=,;

$fun.=;

$error[function]=$fun;

if!isset$error[line]

continue;

$phpMsg[]=arrayfile=str_replacearraySITE_PATH,,array,/,$error[file],line=$error[line],function=$error[function];

self::showError$type,$errorMsg,$phpMsg;

exit;

/**

*记录错误日志

*

*@static

*@accesspublic

*@paramstring$message

*/

publicstaticfunctionwriteErrorLog$message

returnfalse;//暂时不写入

$message=self::clear$message;

$time=time;

$file=LOG_PATH./.dateY.m.d._errorlog.php;

$hash=md5$message;

$userId=0;

$ip=get_client_ip;

$user=User:userId=.intval$userId.;IP=.$ip.;RIP:.$_SERVER[REMOTE_ADDR];

$uri=Request:.htmlspecialcharsself::clear$_SERVER[REQUEST_URI];

$message=t$timet$messaget$hasht$user$urin;

//判断该$message是否在时间间隔$maxtime内已记录过,有,那么不用再记录了

ifis_file$file

$fp=@fopen$file,rb;

$lastlen=50000;//读取结果的$lastlen长度字节内容

$maxtime=60*10;//时间间隔:10分钟

$offset=filesize$file-$lastlen;

if$offset0

fseek$fp,$offset;

if$data=fread$fp,$lastlen

$array=exploden,$data;

ifis_array$array

foreach$arrayas$key=$val

$row=explodet,$val;

if$row[0]!=

continue;

if$row[3]==$hash$row[1]$time-$maxtime

return;

error_log$message,3,$file;

/**

*除掉文本片面字符

*

*@paramstring$message

*/

publicstaticfunctionclear$message

returnstr_replacearrayt,r,n,,$message;

/**

*sql语句字符清理

*

*@static

*@accesspublic

*@paramstring$message

*@paramstring$dbConfig

*/

publicstaticfunctionsqlClear$message,$dbConfig

$message=self::clear$message;

if!definedSITE_DEBUGSITE_DEBUG

$message=str_replace$dbConfig[database],***,$message;

//$message=str_replace$dbConfig[prefix],***,$message;

$message=str_replaceCDB_PREFIX,***,$message;

$message=htmlspecialchars$message;

return$message;

/**

*显示错误

*

*@static

*@accesspublic

*@paramstring$type错误类型db,system

*@paramstring$errorMsg

*@paramstring$phpMsg

*/

publicstaticfunctionshowError$type,$errorMsg,$phpMsg=

global$_G;

$errorMsg=str_replaceSITE_PATH,,$errorMsg;

ob_end_clean;

$host=$_SERVER[HTTP_HOST];

$title=$type==db?Database:System;

echo

$titleError

$errorMsg

EOT;

if!empty$phpMsg

echo

;

echo

PHPDebug

;

echo;ifis_array$ph

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论