From e0d2602443d000c9d7a1953e8e282bf572e68ac9 Mon Sep 17 00:00:00 2001 From: Gaetano Giunta Date: Thu, 26 Jan 2017 11:05:39 +0000 Subject: [PATCH] Fix EZP-26907: avoid 'mysql has gone away' errors --- bin/php/updatesearchindexsolr.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bin/php/updatesearchindexsolr.php b/bin/php/updatesearchindexsolr.php index 88b91057..cc8001c1 100755 --- a/bin/php/updatesearchindexsolr.php +++ b/bin/php/updatesearchindexsolr.php @@ -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 ) { @@ -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 ) {