<i id='0mOTJ'><tr id='0mOTJ'><dt id='0mOTJ'><q id='0mOTJ'><span id='0mOTJ'><b id='0mOTJ'><form id='0mOTJ'><ins id='0mOTJ'></ins><ul id='0mOTJ'></ul><sub id='0mOTJ'></sub></form><legend id='0mOTJ'></legend><bdo id='0mOTJ'><pre id='0mOTJ'><center id='0mOTJ'></center></pre></bdo></b><th id='0mOTJ'></th></span></q></dt></tr></i><div id='0mOTJ'><tfoot id='0mOTJ'></tfoot><dl id='0mOTJ'><fieldset id='0mOTJ'></fieldset></dl></div>
  1. <legend id='0mOTJ'><style id='0mOTJ'><dir id='0mOTJ'><q id='0mOTJ'></q></dir></style></legend>

    <small id='0mOTJ'></small><noframes id='0mOTJ'>

      <bdo id='0mOTJ'></bdo><ul id='0mOTJ'></ul>
    <tfoot id='0mOTJ'></tfoot>

    1. 守护进程中的 Doctrine2 连接超时

      Doctrine2 connection timeout in daemon(守护进程中的 Doctrine2 连接超时)
        <i id='rvfJX'><tr id='rvfJX'><dt id='rvfJX'><q id='rvfJX'><span id='rvfJX'><b id='rvfJX'><form id='rvfJX'><ins id='rvfJX'></ins><ul id='rvfJX'></ul><sub id='rvfJX'></sub></form><legend id='rvfJX'></legend><bdo id='rvfJX'><pre id='rvfJX'><center id='rvfJX'></center></pre></bdo></b><th id='rvfJX'></th></span></q></dt></tr></i><div id='rvfJX'><tfoot id='rvfJX'></tfoot><dl id='rvfJX'><fieldset id='rvfJX'></fieldset></dl></div>
      1. <legend id='rvfJX'><style id='rvfJX'><dir id='rvfJX'><q id='rvfJX'></q></dir></style></legend>

              <bdo id='rvfJX'></bdo><ul id='rvfJX'></ul>
            • <tfoot id='rvfJX'></tfoot>

              <small id='rvfJX'></small><noframes id='rvfJX'>

                  <tbody id='rvfJX'></tbody>

                本文介绍了守护进程中的 Doctrine2 连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个长时间运行的守护进程(Symfony2 命令),它从 Redis 的工作队列中获取工作,并使用 orm 执行这些工作并写入数据库.

                I have a long running daemon (Symfony2 Command) that gets work off a work queue in Redis, and performs those jobs and writes to the database using the orm.

                我注意到,当工作人员空闲等待工作时,工作人员有死亡的趋势,因为与 MySQL 的连接超时.

                I noticed that when that there is a tendency for the worker to die because the connection to MySQL timed out when worker is idling waiting for work.

                具体来说,我在日志中看到了这一点:MySQL 服务器已消失.

                Specifically, I see this in the log: MySQL Server has gone away.

                无论如何我可以让学说自动重新连接吗?或者有什么方法可以手动捕获异常并重新连接学说orm?

                Is there anyway I can have doctrine automatically reconnect? Or is there some way I can manually catch the exception and reconnect the doctrine orm?

                谢谢

                推荐答案

                似乎每当 Doctrine 中的 EntityManager 遇到任何错误/异常时,连接都会关闭并且 EntityManager 已死亡.

                It appears that whenever there is any error/exception encountered by the EntityManager in Doctrine, the connection is closed and the EntityManager is dead.

                由于通常所有内容都包含在一个事务中,并且该事务在调用 $entityManager->flush() 时执行,因此您可以尝试捕获异常并尝试重新执行或放弃.

                Since generally everything is wrapped in a transaction and that transaction is executed when $entityManager->flush() is called, you can try and catch the exception and attempt to re-excute or give up.

                您可能希望通过更具体的类型捕获来检查异常的确切性质,无论是 PDOException 还是其他类型.

                You may wish to examine the exact nature of the exception with more specific catch on the type, whether PDOException or something else.

                对于 MySQL has Gone Away 异常,您可以尝试通过重置 EntityManager 重新连接.

                For a MySQL has Gone Away exception, you can try to reconnect by resetting the EntityManager.

                $managerRegistry = $this->getContainer()->get('doctrine');
                $em = $managerRegistry->getEntityManager();
                $managerRegistry->resetEntityManager();
                

                这应该使 $em 再次可用.请注意,您必须再次重新持久化所有内容,因为 $em 是新的.

                This should make the $em usable again. Note that you would have to re-persist everything again, since this $em is new.

                这篇关于守护进程中的 Doctrine2 连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                How to parse django style template tags(如何解析 django 样式模板标签)
                What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                php in background exec() function(php 后台 exec() 函数)

                <small id='1FxNZ'></small><noframes id='1FxNZ'>

                  <tbody id='1FxNZ'></tbody>
                  <i id='1FxNZ'><tr id='1FxNZ'><dt id='1FxNZ'><q id='1FxNZ'><span id='1FxNZ'><b id='1FxNZ'><form id='1FxNZ'><ins id='1FxNZ'></ins><ul id='1FxNZ'></ul><sub id='1FxNZ'></sub></form><legend id='1FxNZ'></legend><bdo id='1FxNZ'><pre id='1FxNZ'><center id='1FxNZ'></center></pre></bdo></b><th id='1FxNZ'></th></span></q></dt></tr></i><div id='1FxNZ'><tfoot id='1FxNZ'></tfoot><dl id='1FxNZ'><fieldset id='1FxNZ'></fieldset></dl></div>
                  • <tfoot id='1FxNZ'></tfoot>
                      <bdo id='1FxNZ'></bdo><ul id='1FxNZ'></ul>

                      <legend id='1FxNZ'><style id='1FxNZ'><dir id='1FxNZ'><q id='1FxNZ'></q></dir></style></legend>