sfErrorNotifierPlugin:“默认”插件上下文不存在
我已经安装了sfErrorNotifierPlugin
。当两个选项reportErrors/reportPHPErrorsreportPHPWarnings/reportWarnings都设置为false时,一切正常。但我想捕获 PHP 异常和警告来接收电子邮件,但随后我的所有任务都失败了,包括清除缓存。经过几个小时的测试后,我 100% 确定问题出在 set_exception_handler/set_error_handler 上。
有一个类似的问题: symfony 任务上的 sfErrorNotifierPlugin 但作者在那里自定义任务遇到问题。就我而言,即使内置任务也会失败。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我没有使用过 sfErrorNotifierPlugin,但我遇到了““默认”上下文不存在”的情况。之前的消息。当调用
sfContext::getInstance()
并且上下文根本不存在时,就会发生这种情况。我在自定义任务中经常发生这种情况。一种解决方案是在调用sfContext::getInstance()
之前添加sfContext::createInstance()
。这将确保上下文存在。有一篇关于“为什么 sfContext::getInstance() 不好”的有趣博客文章,其中详细介绍了 - http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/
I haven't used sfErrorNotifierPlugin, but I have run into 'The “default” context does not exist.' messages before. It happens when a call is made to
sfContext::getInstance()
and the context simply doesn't exist. I've had this happen a lot from within custom tasks. One solution is to addsfContext::createInstance()
before the call tosfContext::getInstance()
. This will ensure that a context exists.There's an interesting blog post on 'Why sfContext::getInstance() is bad' that goes into more detail - http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/
不幸的是,这个问题无法通过这种方式解决。使用 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):
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).
Arms正确地解释了这个问题。但在控制台上执行后端/维护任务时通常不存在上下文。如果你自己处理这种情况会更容易。
检查一下,您是否真的需要上下文?
如果需要,您到底需要它做什么?
有时您只希望用户填充created_by字段。您可以通过对用户 ID 进行硬编码来解决此问题。
如果您想做一些更集成的事情,请创建一个页面(将具有上下文)并从那里触发任务。
Arms has explained the problem correctly. But usually context does not exist when executing backend/maintenance tasks on the console. And it is easier if you handle the condition yourself.
Check, if you really need the context?
If you do, what exactly do you need it for?
Sometimes you only want a user to populate a created_by field. You can work around by hard-coding a user ID.
If you want to do something more integrated, create a page (which will have a context) and trigger the task from there.
您可以在类内执行某些操作之前测试实例是否存在。喜欢:
you can test the existance of the instance before doing something inside a class. Like:
我在使用插件 sfErrorNotifier 时遇到了同样的问题。
在我的具体情况下,我注意到出现了警告:
警告:ob_start():在 /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration 中找不到函数“”或无效的函数名称。 class.php 第 155 行
注意:ob_start(): 未能在中创建缓冲区/var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php 第 155 行
因此,检查文件:sfApplicationConfiguration.class.php 类,第 155 行,
我已将 ' ' 替换为 null,然后警告消失,错误也消失!
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
坏ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null);
好I've been experiencing the same problem using the plugin sfErrorNotifier.
In my specific case, I noticed a warning was raised:
Warning: ob_start(): function '' not found or invalid function name in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
Notice: ob_start(): failed to create buffer in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
So, checking the file: sfApplicationConfiguration.class.php class, line 155,
I've replaced the ' ' for a null, then the warnings disappears, and also the error!
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
badob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null);
good