在此先感谢您的帮助。
我想知道是否有人很快知道在实体存储库死机时要调用哪些函数来重新连接。我正在通过 ZF2 CLI 路由运行一些作业,这些作业可能需要超过 wait_timeout 的时间,不幸的是,ER 的连接在需要使用时(作业完成时)就断开了。
Need:
// do the long job
$sl = $this->getServiceLocator();
$mapper = $sl->get( 'doctrine_object_mapper' );
if( !$mapper->getRepository()->isAlive() ) // something like so
$mapper->getRepository()->wakeTheHellUp();
这些不是正确的方法名称吗! ;)
再次感谢。
这是一个相当普遍的问题具有长时间运行的进程和连接。
解决方案是检索 ORMDBAL 连接并在连接丢失时重新创建它(确保它在事务期间不会终止)。这显然很烦人,但这是目前唯一的方法:
// 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)