<legend id='FTtf5'><style id='FTtf5'><dir id='FTtf5'><q id='FTtf5'></q></dir></style></legend>

      <tfoot id='FTtf5'></tfoot>
    1. <i id='FTtf5'><tr id='FTtf5'><dt id='FTtf5'><q id='FTtf5'><span id='FTtf5'><b id='FTtf5'><form id='FTtf5'><ins id='FTtf5'></ins><ul id='FTtf5'></ul><sub id='FTtf5'></sub></form><legend id='FTtf5'></legend><bdo id='FTtf5'><pre id='FTtf5'><center id='FTtf5'></center></pre></bdo></b><th id='FTtf5'></th></span></q></dt></tr></i><div id='FTtf5'><tfoot id='FTtf5'></tfoot><dl id='FTtf5'><fieldset id='FTtf5'></fieldset></dl></div>

      <small id='FTtf5'></small><noframes id='FTtf5'>

          <bdo id='FTtf5'></bdo><ul id='FTtf5'></ul>
      1. PHP 中的错误处理

        时间:2023-09-21

          <small id='r1MQH'></small><noframes id='r1MQH'>

          <tfoot id='r1MQH'></tfoot>
            <tbody id='r1MQH'></tbody>
        1. <legend id='r1MQH'><style id='r1MQH'><dir id='r1MQH'><q id='r1MQH'></q></dir></style></legend>

            <i id='r1MQH'><tr id='r1MQH'><dt id='r1MQH'><q id='r1MQH'><span id='r1MQH'><b id='r1MQH'><form id='r1MQH'><ins id='r1MQH'></ins><ul id='r1MQH'></ul><sub id='r1MQH'></sub></form><legend id='r1MQH'></legend><bdo id='r1MQH'><pre id='r1MQH'><center id='r1MQH'></center></pre></bdo></b><th id='r1MQH'></th></span></q></dt></tr></i><div id='r1MQH'><tfoot id='r1MQH'></tfoot><dl id='r1MQH'><fieldset id='r1MQH'></fieldset></dl></div>
              <bdo id='r1MQH'></bdo><ul id='r1MQH'></ul>
                1. 本文介绍了PHP 中的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我熟悉一些基础知识,但我想了解更多关于何时以及为什么应该在 PHP 中使用错误处理(包括抛出异常),尤其是在实时站点或 Web 应用程序中.它是否可以被过度使用,如果是,过度使用是什么样的?是否有不应该使用的情况?另外,在错误处理方面有哪些常见的安全问题?

                  I'm familiar with some of the basics, but what I would like to know more about is when and why error handling (including throwing exceptions) should be used in PHP, especially on a live site or web app. Is it something that can be overused and if so, what does overuse look like? Are there cases where it shouldn't be used? Also, what are some of the common security concerns in regard to error handling?

                  推荐答案

                  要补充已经说过的一件事是,将 Web 应用程序中的任何错误记录到日志中是最重要的.这样,正如 Jeff Coding Horror" Atwood 所建议的那样,当您的用户在使用您的应用程序时遇到问题时,您就会知道(而不是询问他们出了什么问题").

                  One thing to add to what was said already is that it's paramount that you record any errors in your web application into a log. This way, as Jeff "Coding Horror" Atwood suggests, you'll know when your users are experiencing trouble with your app (instead of "asking them what's wrong").

                  为此,我推荐以下类型的基础设施:

                  To do this, I recommend the following type of infrastructure:

                  • 在您的数据库中创建一个崩溃"表和一组用于报告错误的包装类.我建议为崩溃设置类别(阻塞"、安全"、PHP 错误/警告"(与异常)等).
                  • 在您的所有错误处理代码中,确保记录错误.始终如一地执行此操作取决于您构建 API(上述步骤)的程度 - 如果操作正确,记录崩溃应该微不足道.

                  额外的功劳:有时,您的崩溃将是数据库级别的崩溃:即数据库服务器关闭等.如果是这种情况,您的错误记录基础架构(以上)将失败(您无法将崩溃记录到数据库中,因为日志尝试写入数据库).在这种情况下,我会在您的 Crash 包装器类中将故障转移逻辑编写为

                  Extra credit: sometimes, your crashes will be database-level crashes: i.e. DB server down, etc. If that's the case, your error logging infrastructure (above) will fail (you can't log the crash to the DB because the log tries to write to the DB). In that case, I would write failover logic in your Crash wrapper class to either

                  • 向管理员发送电子邮件,和/或
                  • 将崩溃的详细信息记录到纯文本文件中

                  所有这些听起来都有些矫枉过正,但相信我,这会影响您的应用程序是被接受为稳定"还是不稳定".这种差异源于这样一个事实,即所有应用程序一开始都是不稳定/崩溃的,但那些了解其应用程序所有问题的开发人员有机会实际修复它.

                  All of this sounds like an overkill, but believe me, this makes a difference in whether your application is accepted as a "stable" or "flaky". That difference comes from the fact that all apps start as flaky/crashing all the time, but those developers that know about all issues with their app have a chance to actually fix it.

                  这篇关于PHP 中的错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:处理 php 页面错误的最佳方法? 下一篇:使用 PDO 处理错误的最佳实践

                  相关文章

                  最新文章

                  1. <tfoot id='HzL9T'></tfoot>
                    1. <legend id='HzL9T'><style id='HzL9T'><dir id='HzL9T'><q id='HzL9T'></q></dir></style></legend>

                      <small id='HzL9T'></small><noframes id='HzL9T'>

                        <bdo id='HzL9T'></bdo><ul id='HzL9T'></ul>
                      <i id='HzL9T'><tr id='HzL9T'><dt id='HzL9T'><q id='HzL9T'><span id='HzL9T'><b id='HzL9T'><form id='HzL9T'><ins id='HzL9T'></ins><ul id='HzL9T'></ul><sub id='HzL9T'></sub></form><legend id='HzL9T'></legend><bdo id='HzL9T'><pre id='HzL9T'><center id='HzL9T'></center></pre></bdo></b><th id='HzL9T'></th></span></q></dt></tr></i><div id='HzL9T'><tfoot id='HzL9T'></tfoot><dl id='HzL9T'><fieldset id='HzL9T'></fieldset></dl></div>