在生产环境中进行严重使用时,debug_backtrace()是否安全? [英] Is debug_backtrace() safe for serious usage in production environment?
问题描述
它的功能是如此强大,以至于我担心它的稳定性和性能.
It's functionality is so strong that I worry about its stability and performance.
您怎么看?
更新
我正在做什么:
$old_dir = getcwd();
chdir( dirname($included_file) );
include ( $included_file );
chdir( $old_dir );
从本质上讲它只是做include ( $included_file );
,但是在$included_file
里面找不到与它所在目录相同的3.php
,所以我手动设置了cwd并且它起作用了.如果找到无法找到它的原因,这是很好的.至于为什么需要debug_backtrace
,这是因为3.php
被另一个func
包含了,因为相对路径不起作用,所以必须使用
Essentially it just does include ( $included_file );
,but inside that $included_file
it can't find 3.php
which is in the same directory as itself is in,so I manually set the cwd and it works.But it would be nice if I find the reason why it can't find.As for why debug_backtrace
is needed,it's because 3.php
is included by another func
,since the relative path doesn't work,it has to use debug_backtrace
to get the including file path,finally using the absolute path as mentioned below.
复制起来并不容易,因为上面的代码是在方法的上下文中,还有更多的内容.如果没有其他人遇到过这种问题,我想在这里停下来,无论如何,成本只是额外的3条线,没什么大不了的.
It's not easy to reproduce,as the above code is in the context of a method,and much more..If no one else has met this kinda problem I'd like to just stop here,anyway,the cost is just the 3 extra lines,not a big deal.
推荐答案
debug_backtrace
相对昂贵,因此您应注意不要将其用于循环中(例如,在捕获警告或通知的自定义错误处理程序中)并每次执行回溯.)
debug_backtrace
is relatively expensive in my experience, so you should be careful it is not used in loops (e.g. in a custom error handler that catches warnings or notices and performs a backtrace every time).
对于任何类型的错误日志记录,我认为它都是非常宝贵的,并且因为它将仅被调用一次,所以绝对不是性能问题.在错误报告中包含回溯肯定是一件好事.
For any kind of error logging, I think it's pretty invaluable, and because it's going to be called only once, definitely not a performance problem. It is surely always good to include a backtrace in an error report.
我看不出为什么此功能的稳定性会有任何特定的问题(即称它导致另一个崩溃),我从未听说过任何问题.我看到的唯一陷阱"是用户中的此注释使用对象作为未定义_toString
方法的函数参数时的注释.
I can't see why there would be any specific issues with this function's stability (i.e. calling it causing another crash), I've never heard of any problems. The only "gotcha" I can see is this note in the User Contributed Notes when using objects as function parameters that have no _toString
method defined.
当然,您永远不应将回溯的结果输出给最终用户-不用说.
Of course, you should never output the results of a backtrace to the end user - that goes without saying.
这篇关于在生产环境中进行严重使用时,debug_backtrace()是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!