gpt4 book ai didi

Debugging PHP production application with XDebug when need?(在需要时使用XDebug调试PHP生产应用程序?)

转载 作者:bug小助手 更新时间:2023-10-25 11:24:20 25 4
gpt4 key购买 nike



I have a question on debugging PHP application using XDebug in production and would like to have your idea.

我有一个关于在生产中使用XDebug调试PHP应用程序的问题,想知道你的想法。


We all know that even if the testing and production environments are identical, we still have bugs that exists in Production but not testing.

我们都知道,即使测试和生产环境是相同的,我们仍然有存在于生产中但不存在于测试中的错误。


So, is that possible to show XDebug detail information/profiling ONLY when pass in something like enable_debug=1 in URL, and XDebug will show every custom debug information possible?

那么,是否可以仅在URL中传递类似ENABLE_DEBUG=1内容时才显示XDebug详细信息/分析,且XDebug将显示所有可能的自定义调试信息?


While if there is no such parameters, everything is running just like normal.

而如果没有这些参数,一切都像正常一样运行。


Can XDebug do that? If not, what other debugging program can do this?

XDebug能做到这一点吗?如果没有,还有什么调试程序可以做到这一点?


Thank you.

谢谢。


P.S. I know clearly that:

另外,我清楚地知道:



  • We cannot put debugging information in production.

  • This is dangerous and not security-friendly when showing debug info in production server.

  • As I said before, Programming is weird. Even we confirm that everything is identical, some bugs will only exists in production but not testing.


更多回答

That's very similar to what the standard XDEBUG_SESSION cookie does already (ref.). I think the most important thing to do is that restrict the whole feature to a set of well known IP addresses. Still, it doesn't feel quite right. Running the Xdebug extension always adds overhead. Many production bugs can be diagnosed with a copy of the database.

这与标准的XDEBUG_SESSION cookie所做的非常相似(参考文献)。我认为最重要的是将整个功能限制在一组众所周知的IP地址上。尽管如此,感觉还是不太对劲。运行XDEBUG扩展总是会增加开销。许多生产错误都可以通过数据库的副本进行诊断。

优秀答案推荐

Yes, you could use GET parameter, like:

可以,您可以使用GET参数,例如:


if ($_GET['enable_debug'] == 1) {
ini_set('display_errors', 1);
ini_set('xdebug.show_error_trace', 1);
ini_set('xdebug.show_exception_trace', 1);
// other XDebug settings...
}

However, this approach doesn't take into account security concerns and might expose sensitive information if the enable_debug parameter is ever unintentionally or maliciously set.

但是,这种方法不考虑安全问题,如果无意或恶意设置了ENABLE_DEBUG参数,则可能会暴露敏感信息。


更多回答

This is not a great idea. You also will need to set xdebug.mode from off to debug,develop, which you can't do with ini_set(). Having xdebug.mode set to anything else in production (which you never should do!) has a performance impact.

这不是一个好主意。您还需要将xdebug.mode从OFF设置为DEBUG、DEVE,这在ini_set()中是做不到的。将xdebug.mode设置为生产中的任何其他值(这是您永远不应该做的!)会对性能产生影响。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com