php try catch错误报告

发布于 2024-09-14 16:31:34 字数 1298 浏览 5 评论 0原文

我有一个依赖肥皂服务器来生成内容的应用程序。此外,站点身份验证基于单独的 LDAP 服务器。显然,如果其中任何一个出现故障或没有响应,则该网站就会出现故障。

我正在尝试设计一种设计,以便我可以向网站管理员报告错误,并在网站关闭时向用户提供一条友好的消息。错误报告实际上只是一封电子邮件、数据库插入或日志到 PHP $_COOKIE、$_SERVER、$_SESSION、$_REQUEST 服务器上的文本文件以及潜在的 SoapFault 异常。如果网站出现任何潜在问题,这些信息将帮助我进行调试。

目前,我的网站设计如下:

SoapClientInterface (defines soap functionality)
      / \
       |
       |   implements
       |
Client (the client implementing the interface, try/catch blocks on all soap calls here) 
      / \
       |
       |  extends
       |
 Authorization (asserts soap objects returned from server/ requests going to server 
               are appropriate for the user performing the request) 
      / \
       |
       | extends
       | 
  {all children classes using the soap interface defined on this level} 

从上面的糟糕图表来看:-)我有一个 Client 类,它包含所有用于处理soapfault异常的 try catch 块,并且我想知道用 catch 做两件事的最佳方法: 1.通知用户操作失败(我的所有功能都在 if/else 块中,如果我确定操作失败,我会将用户重定向到状态页面并通知他们操作失败。
2. 向站点管理员报告情况以进行调试(目前此功能是状态页面中定义的一个简单功能,当状态页面收到错误代码时,我们转储 Cookie、服务器、会话和请求变量,并将其通过电子邮件发送到站点管理员。

对此的任何建议将不胜感激,或者如果您需要澄清,请询问:

根据我的网络编程经验,我的应用程序通常在发生操作的页面上显示用户操作的状态,并且不会重定向到其他地方。这是我第一次编写一个应用程序来执行用户操作并重定向到所有状态消息的单独页面,如果我这样做的话,有人认为为所有站点设置一个状态页面有好处吗?操作或有一个类/函数来报告发生操作的页面上的状态?(我问这个是为了考虑状态页面本身的设计以及如何报告错误等等。)

I have an application which relies on a soap server to produce content. Additionally authentication to the site is based on a separate LDAP server. Obviously if either of these are down or not responding the site is down.

I am trying to lay out a design such that I can have error reporting for site admins and also give a nice message to user's in the case that the site is down. Error reporting is really just an email, database insert or log to text file on server of PHPs $_COOKIE, $_SERVER, $_SESSION, $_REQUEST along with potentially a SoapFault exception. This information would aid me in debugging any potential problems with the site if they occur.

Currently, my site is designed as follows:

SoapClientInterface (defines soap functionality)
      / \
       |
       |   implements
       |
Client (the client implementing the interface, try/catch blocks on all soap calls here) 
      / \
       |
       |  extends
       |
 Authorization (asserts soap objects returned from server/ requests going to server 
               are appropriate for the user performing the request) 
      / \
       |
       | extends
       | 
  {all children classes using the soap interface defined on this level} 

From the poor diagram above :-) I have a class Client which encompasses all of my try catch blocks for soapfault exceptions and am wondering the best way to do two things with the catchs:
1. notify user an action has failed (all of my functionality is in if/else blocks and if I determine an operation has failed I re-direct user to a status page and inform them that their action has failed.
2. report the situation to site admins for debugging (this functionality at the moment is a simple function defined in status page that when status page gets an error code we dump the Cookier, Server, Session, and Request variables and email this off to site admins.

Any suggestions on this would be appreciated or if you need clarification please ask.

EDIT: In my experience with web programming my applications usually display status of user actions on the page in which the action takes place and do not re-direct elsewhere. This is the first time I have coded an application to perform a user action and redirect to a separate page for all status messages. Should I be kicking myself for doing it this way, does anyone see merit in having a single status page for all site actions or having a class/function that reports status on the page in which the action took place? (I am asking this in regards to thinking about the design of status page on its own and how to report errors and what not.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-09-21 16:31:34

嗯,我个人认为这取决于错误。根据我的经验,异常分为三种类型。那些您可以忽略的,那些您可以解决的,以及那些您用来终止执行的(如果您只是尝试删除文件,则可以忽略 file_not_found 异常,一个 如果资源有其他来源,则可以解决resource_not_available异常,并且database_connection_failure异常将需要终止应用程序,除非您有备份)...哪种类型捕获的异常将决定你如何处理它。

就个人而言,我安装了 全局异常处理程序..然后,在我的 catch 块中,我可以选择是否清理请求,以不同的方式处理它,继续(如果它是可恢复的异常),或者如果我无法正确处理它(查询错误等),则重新抛出异常。 )。如果异常到达堆栈顶部(全局处理程序),那么我会记录错误(我为此使用数据库表)并抛出 500 内部服务器错误。

至于重定向错误,我无法忍受。如果错误是暂时错误,那么为什么我不能刷新页面呢?为什么我必须回去(如果我可以的话)再试一次...

只要正确输出缓冲区,您几乎总是能够呈现错误页面而不向用户显示任何敏感信息(我说几乎,因为你不能渲染任何致命错误)...否则你就违反了 HTTP 规范(因为你说有一个来自发生错误的当前页面的临时重定向,而不是正确的“发生错误”状态标头) ...

Well, personally I think it depends on the error. In my experience, there are three types of exceptions. Those that you can ignore, those that you can work around, and those that you use to terminate execution (A file_not_found exception can be ignored if you're just trying to delete the file, a resource_not_available exception may be able to be worked around if there are alternative sources for the resource, and a database_connection_failure exception would require termination of the app unless you had a backup)... Which type of exception was caught will dictate what you do with it.

Personally, I install a global exception handler... Then, in my catch block I can choose whether to clean up the request, handle it differently, continue on (if it's a recoverable exception), or re-throw the exception if I can't handle it properly (Query error, etc). If the exception makes it to the top of the stack (the global handler), then I log the error (I use a database table for this) and throw a 500 internal server error.

As far as redirecting for errors, I can't stand that. If the error is a temporal error, then why can't I just refresh the page? Why must I go back (if I even can) to try again...

As long as you output buffer properly, you should almost always be able to render an error page without displaying any sensitive info to the user (I say almost, since you can't render anything for a fatal error)... Otherwise you're breaking HTTP spec (Since you are saying there's a temporary redirect from the current page where the error occurred rather than the proper "an error occurred" status header)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文