X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/ForkController.php diff --git a/includes/ForkController.php b/includes/ForkController.php index e5b44c2b..2dde17be 100644 --- a/includes/ForkController.php +++ b/includes/ForkController.php @@ -1,4 +1,25 @@ procsToStart = $numProcs; $this->flags = $flags; @@ -49,10 +70,11 @@ class ForkController { * This will return 'child' in the child processes. In the parent process, * it will run until all the child processes exit or a TERM signal is * received. It will then return 'done'. + * @return string */ public function start() { // Trap SIGTERM - pcntl_signal( SIGTERM, array( $this, 'handleTermSignal' ), false ); + pcntl_signal( SIGTERM, [ $this, 'handleTermSignal' ], false ); do { // Start child processes @@ -100,7 +122,9 @@ class ForkController { if ( function_exists( 'pcntl_signal_dispatch' ) ) { pcntl_signal_dispatch(); } else { - declare (ticks=1) { $status = $status; } + declare( ticks = 1 ) { + $status = $status; + } } // Respond to TERM signal if ( $this->termReceived ) { @@ -114,16 +138,33 @@ class ForkController { return 'done'; } + /** + * Get the number of the child currently running. Note, this + * is not the pid, but rather which of the total number of children + * we are + * @return int + */ + public function getChildNumber() { + return $this->childNumber; + } + protected function prepareEnvironment() { - global $wgCaches, $wgMemc; - // Don't share DB or memcached connections - wfGetLBFactory()->destroyInstance(); - $wgCaches = array(); - unset( $wgMemc ); + global $wgMemc; + // Don't share DB, storage, or memcached connections + MediaWikiServices::resetChildProcessServices(); + FileBackendGroup::destroySingleton(); + LockManagerGroup::destroySingletons(); + JobQueueGroup::destroySingletons(); + ObjectCache::clear(); + RedisConnectionPool::destroySingletons(); + $wgMemc = null; } /** * Fork a number of worker processes. + * + * @param int $numProcs + * @return string */ protected function forkWorkers( $numProcs ) { $this->prepareEnvironment(); @@ -139,6 +180,7 @@ class ForkController { if ( !$pid ) { $this->initChild(); + $this->childNumber = $i; return 'child'; } else { // This is the parent process