Skip to content

Commit

Permalink
Fix EZP-26907: avoid 'mysql has gone away' errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetano Giunta committed Jan 27, 2017
1 parent 20f281e commit e0d2602
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bin/php/updatesearchindexsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ protected function iterate( $count = false )
* @param int $nodeid
* @param int $offset
* @param int $limit
* @return int
*/
protected function forkAndExecute( $nodeID, $offset, $limit )
{
Expand All @@ -363,10 +364,34 @@ protected function forkAndExecute( $nodeID, $offset, $limit )
// Prepare DB-based cluster handler for fork (it will re-connect DB automatically).
eZClusterFileHandler::preFork();

$conns = false;
$ezpKernelContainer = ezpKernel::instance()->getServiceContainer();
if ( $ezpKernelContainer ) // in case we are in pure-legacy mode
{
$conns = $ezpKernelContainer->get('doctrine')->getConnections();
foreach( $conns as $name => $conn )
{
if ( $conn->isConnected() )
{
$conn->close();
}
else
{
unset( $conns[$name] );
}
}
}

$pid = pcntl_fork();

// reinitialize DB after fork
$this->initializeDB();
if ( $conns )
{
foreach( $conns as $conn ) {
$conn->connect();
}
}

if ( $pid == -1 )
{
Expand Down

0 comments on commit e0d2602

Please sign in to comment.