问题描述
我已经安装了sfErrorNotifierPlugin
.当两个选项reportErrors/reportPHPErrors reportPHPWarnings/reportWarnings都设置为false时,一切正常.但是我想捕获PHP异常和警告以接收电子邮件,但是随后我的所有任务都失败了,包括清除缓存.经过几个小时的测试,我100%确定问题出在set_exception_handler/set_error_handler.
I have installed the sfErrorNotifierPlugin
. When both options reportErrors/reportPHPErrors reportPHPWarnings/reportWarnings are set to false, everything is ok. But I want to catch PHP exceptions and warnings to receive E-mails, but then all my tasks fail, including clear-cache. After few hours of tests I'm 100% sure that the problem is with set_exception_handler/set_error_handler.
还有一个类似的问题: symError任务上的sfErrorNotifierPlugin ,但是作者在那里自定义任务遇到问题.就我而言,即使内置任务也会失败.
There's a similar question:sfErrorNotifierPlugin on symfony task but the author there is having problems with a custom task. In my case, even built-in tasks fail.
推荐答案
很遗憾,这种方法无法解决问题.使用sfErrorNotifierPlugin,我启用了报告PHP警告/错误的报告(除了symfony异常),这导致了巨大的问题,例如诸如清除缓存之类的内置任务失败.
Well, the problem could not be solved this way, unfortunately. Using sfErrorNotifierPlugin, I have enabled reporting PHP warning/errors (apart from symfony exceptions) and this resulted in huge problems, e.g. built-in tasks such as clear-cache failed.
我选择的解决方案是仅以非任务模式(项目配置类)加载插件:
The solution I chose was to load the plugin only in non-task mode (project configuration class):
public function setup()
{
$this->enableAllPluginsExcept('sfPropelPlugin');
if ('cli' == php_sapi_name()) $this->disablePlugins('sfErrorNotifierPlugin');
}
执行任务后,一切正常.从浏览器启动应用程序时,在发生异常/警告(也许有人会发现它有用)时会发送电子邮件.
WHen a task is executed, everything works normally. When an app is fired from the browser, emails are sent when exception/warning occurs (maybe someone will find it useful).
这篇关于sfErrorNotifierPlugin:“默认"标记为上下文不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!