PHP:如何在生产网站上禁用异常消息并将其保留在开发环境中? [英] PHP: How can we disable exception messages on production website and keep them in dev?

查看:184
本文介绍了PHP:如何在生产网站上禁用异常消息并将其保留在开发环境中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在生产网站上禁用异常消息并将其保留在开发人员中?

How can be disable exception messages on the production website and keep them in dev?

示例:

try{
  //some code
}

catch(Exception $e){
   echo $e.getMessage();
}






>编辑:


Edit:

如何在 Zend Framework 上完成? (.ini文件,但应该写的例外代码怎么样?)

How it done on Zend Framework? (.ini file but what about exception code that should be write?)

编辑2:

如果我的示例无法使用zend框架在application.ini中禁用异常消息?

If my example can't work how zend framework disable exception messages in application.ini?

resources.frontController.params.displayExceptions = 0


推荐答案

我不确定如果我们让你正确。

I'm not sure if we are getting you right.

其他答案告诉你是否抛出关于环境设置的异常。

The other answers tell how whether to throw or not the Exception regarding the environment setting.

答案很简单:
应该总是抛出异常,而不是环境。

The answer is simple: The exceptions should be thrown always, not regarding the environment.

如果你需要您可能会以不同的方式处理它们,但您应该避免有条件的例外。

If you need, you may handle them differently, but you should avoid conditional exceptions.

有很多方法可以在您的应用程序中设置错误处理:

There are many ways, you may set up error handling in your app:


  • ini设置在apache或 .htaccess 配置

  • 使用通过php函数进行相同的设置(例如 e rror_reporting()

  • 配置您的前端控制器(使用 application.ini 或获取前端控制器实例更新ZF的默认错误处理程序

  • 创建自己的错误处理程序

  • >
  • ini settings in apache or .htaccess config
  • using the same settings via php functions (e.g. error_reporting())
  • configuring your front controller (using application.ini or getting front controller instance in Bootstrap)
  • update ZF's default error handler
  • create your own error handler

最简单的似乎是 application.ini

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.throwExceptions = 1
resources.frontController.params.displayExceptions = 1

application.ini 您可以在需要时使用零。

In development section of application.ini you may use zeros where needed.

我建议使用日志应用程序资源来处理生产环境中的例外。

I recommend using Log Application resource to handle the exceptions on the production environment.

这篇关于PHP:如何在生产网站上禁用异常消息并将其保留在开发环境中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆