【问题标题】:Automatic bug collection from PHP/apache server code从 PHP/apache 服务器代码自动收集错误
【发布时间】:2009-01-29 15:03:14
【问题描述】:
【问题讨论】:
标签:
php
apache
bug-tracking
【解决方案1】:
您可以指定自己的自定义 PHP 错误处理程序。这是一个简单的例子:
function log_error_handler($errno, $str, $file, $line)
{
switch($errno) {
case E_USER_ERROR:
add_log("PHP Error", "Error $errno on line $line in $file: $str", "fatal");
exit(1);
break;
case E_USER_WARNING:
add_log("PHP Warning", "Warning $errno on line $line in $file: $str", "warning");
break;
case E_USER_NOTICE:
add_log("PHP Notice", "Notice $errno on line $line in $file: $str", "note");
break;
default:
//uncomment this next line to catch
// add_log("PHP", "Unknown error $errno on line $line in $file: $str", "note");
break;
}
}
function add_log($code, $message, $type = 'message', $program = null ){
//do something like email the admin or enter in the data in to the bug tracking software db
}
// ### function to log php errors ####
set_error_handler("log_error_handler");
【解决方案2】:
我们在我们的服务器上使用 Zend 平台。它不是免费的,但效果很好,可以满足您的大部分需求。
它允许您定义事件和设置触发器。触发时会记录应用程序的整个状态。您可以浏览和过滤事件类型的图表或列表、将事件标记为重复、查看源代码等。
最好的一点是:由于整个事件都是捕获的,因此您只需单击一下即可调试该事件。应用程序的状态(代码、会话、变量、cookie 甚至上传的文件)被发送到 Eclipse 并暂停。然后,您可以单步执行代码以查看错误发生时应用程序的确切状态。对于根本原因分析非常有用。如果需要,您可以在开发服务器上重放错误,这样就不会干扰生产。
【解决方案3】:
忽略错误发生的时间,获取错误信息的 md5 哈希。
检查该 MD5 哈希是否已在您的错误数据库中。
如果没有,请添加它。
如果是,也许你想附加这次发生的日期。
这很棘手,除非您非常擅长使用 error_log() 函数。
您可以就约定达成一致,例如:
error_log('ename:'.$error_name.' emessage:'.$e->toString());
这样您就可以使用相同的ename 和emessage 的MD5 来解析和分组任何错误。