I have a Symfony 2.2 application that has a Command that forks children to process entities in the DB. I'm having a hard time figuring out the proper way to force Doctrine to reconnect in each forked child process.
I finally got one solution working (I can see a new DB connection in my dev.log for each child) but I'm not sure if it's the best way to do it. I pass the container to each child who then creates a new connection and sets the default_connection service with that connection. But this seems a little messy. Any other thoughts on this?
$conn = $this->container->get('doctrine')->getConnection();
$conn2 = \Doctrine\DBAL\DriverManager::getConnection($conn->getParams(), $conn->getConfiguration(), $conn->getEventManager());
$this->container->set('doctrine.dbal.default_connection', $conn2);
$this->doctrine = $this->container->get('doctrine');
$this->doctrine->resetManager();
I don't like the idea of modifying the default_connection, even though this is done in a child process and won't affect the parent. Just seems unclean.