作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
预先感谢您的帮助。
我想知道是否有人很快知道在实体存储库死机时调用哪些函数来启动它的重新连接。我正在运行一些作业,通过 ZF2 CLI 路由可能需要超过 wait_timeout 的时间长度,不幸的是,ER 的连接在需要使用时(作业完成时)终止。
需要:
// do the long job
$sl = $this->getServiceLocator();
$mapper = $sl->get( 'doctrine_object_mapper' );
if( !$mapper->getRepository()->isAlive() ) // something like so
$mapper->getRepository()->wakeTheHellUp();
这些不是正确的方法名称吗! ;)
再次感谢。
最佳答案
这是一个 fairly common problem具有长时间运行的进程和连接。
解决方案是检索 ORM 的 DBAL connection并在连接丢失时重新创建它(确保它在交易期间没有死亡)。这显然很烦人,但这是目前唯一的方法:
// note - you need a ServiceManager here, not just a generic service locator
$entityMAnager = $serviceManager->get('entity_manager');
$connection = $entityManager->getConnection();
try {
// dummy query
$connection->query('SELECT 1');
} catch (\Doctrine\DBAL\DBALException $e) {
if ($connection->getTransactionIsolation()) {
// failed in the middle of a transaction - this is serious!
throw $e;
}
// force instantiation of a new entity manager
$entityManager = $serviceManager->create('entity_manager');
}
$this->doFoo($entityManager);
关于doctrine-orm - ZF2 + Doctrine2 : Server has gone away - how to jog an old connection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15362070/
预先感谢您的帮助。 我想知道是否有人很快知道在实体存储库死机时调用哪些函数来启动它的重新连接。我正在运行一些作业,通过 ZF2 CLI 路由可能需要超过 wait_timeout 的时间长度,不幸的是
预先感谢您的帮助。 我想知道是否有人很快知道在实体存储库死机时调用哪些函数来启动它的重新连接。我正在运行一些作业,通过 ZF2 CLI 路由可能需要超过 wait_timeout 的时间长度,不幸的是
我是一名优秀的程序员,十分优秀!