*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* Class for managing forking command line scripts.
const RESTART_ON_ERROR = 1;
public function __construct( $numProcs, $flags = 0 ) {
- if ( PHP_SAPI != 'cli' ) {
+ if ( !wfIsCLI() ) {
throw new MWException( "ForkController cannot be used from the web." );
}
$this->procsToStart = $numProcs;
$this->termReceived = false;
}
} while ( count( $this->children ) );
-
- $this->initProcess();
+ pcntl_signal( SIGTERM, SIG_DFL );
return 'done';
}
protected function prepareEnvironment() {
global $wgMemc;
- $wgMemc = null; // TODO: change all code that accesses this directly!
-
- // NOTE: we want to destroy global service instances before forking,
- // so no external resources such as database connections get copied
- // to the child processes.
- \MediaWiki\MediaWikiServices::disableStorageBackend();
+ // Don't share DB, storage, or memcached connections
+ MediaWikiServices::resetChildProcessServices();
+ FileBackendGroup::destroySingleton();
+ LockManagerGroup::destroySingletons();
+ JobQueueGroup::destroySingletons();
+ ObjectCache::clear();
+ RedisConnectionPool::destroySingletons();
+ $wgMemc = null;
}
/**
}
if ( !$pid ) {
- $this->initProcess();
+ $this->initChild();
$this->childNumber = $i;
return 'child';
} else {
return 'parent';
}
- protected function initProcess() {
- // Reset services, so we don't re-use connections.
- \MediaWiki\MediaWikiServices::resetChildProcessServices();
-
+ protected function initChild() {
+ global $wgMemc, $wgMainCacheType;
+ $wgMemc = wfGetCache( $wgMainCacheType );
$this->children = null;
pcntl_signal( SIGTERM, SIG_DFL );
}