sfErrorNotifierPlugin:“默认”插件上下文不存在

发布于 2024-11-09 14:58:16 字数 461 浏览 0 评论 0 原文

我已经安装了sfErrorNotifierPlugin。当两个选项reportErrors/reportPHPErrorsreportPHPWarnings/reportWarnings都设置为false时,一切正常。但我想捕获 PHP 异常和警告来接收电子邮件,但随后我的所有任务都失败了,包括清除缓存。经过几个小时的测试后,我 100% 确定问题出在 set_exception_handler/set_error_handler 上。

有一个类似的问题: symfony 任务上的 sfErrorNotifierPlugin 但作者在那里自定义任务遇到问题。就我而言,即使内置任务也会失败。

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.

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.

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

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

发布评论

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

评论(5

青瓷清茶倾城歌 2024-11-16 14:58:16

我没有使用过 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 add sfContext::createInstance() before the call to sfContext::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/

负佳期 2024-11-16 14:58:16

不幸的是,这个问题无法通过这种方式解决。使用 sfErrorNotifierPlugin,我启用了报告 PHP 警告/错误(除了 symfony 异常),这导致了巨大的问题,例如清除缓存等内置任务失败。

我选择的解决方案是仅在非任务模式(项目配置类)下加载插件:

  public function setup()
  {
    $this->enableAllPluginsExcept('sfPropelPlugin');
    if ('cli' == php_sapi_name()) $this->disablePlugins('sfErrorNotifierPlugin');
  }

当执行任务时,一切正常。当从浏览器启动应用程序时,发生异常/警告时会发送电子邮件(也许有人会发现它有用)。

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).

长梦不多时 2024-11-16 14:58:16

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.

ぃ弥猫深巷。 2024-11-16 14:58:16

您可以在类内执行某些操作之前测试实例是否存在。喜欢:

if(sfContext::hasInstance())
  $this->microsite_id = sfContext::getInstance()->getUser()->getAttribute('active_microsite');

you can test the existance of the instance before doing something inside a class. Like:

if(sfContext::hasInstance())
  $this->microsite_id = sfContext::getInstance()->getUser()->getAttribute('active_microsite');
季末如歌 2024-11-16 14:58:16

我在使用插件 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' : ''); bad

ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null); good

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