




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本文格式为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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 诊断测评与BOPPPS教学模式的融合在高中英语阅读教学中的行动研究
- 茶具设计手绘技法解析
- 肾病综合征常规护理要点
- 孕期饮食健康管理
- 大班心理健康:笑是良药
- 领航职业英语2课件下载
- 恶性肿瘤病人的护理教学查房
- 2025年上海市中考招生考试数学真题试卷(真题+答案)
- 采样消毒培训
- 舞蹈教育考研讲解
- 急性上消化道出血Blatchford评分
- DB12-T368-2008卤虫池塘养殖技术规范
- TSG11-2020 锅炉安全技术规程
- 航图zbyn太原武宿-机场细则
- 浙江省城市体检工作技术导则(试行)
- 义务教育历史课程标准(2022年版)
- DVD在线租赁-2005年全国大学生数学建模大赛B题全国一等奖论文
- 防火封堵施工方案(新版)
- 真空度正压和负压关系及负压中MPa和Pa对应关系
- 大面积地面荷载作用附加沉降量计算
- 山东省普通初中小学音乐、美术、卫生设备配备标准
评论
0/150
提交评论