X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FForkController.php;h=cc16964e1fdd36a24d9f030692c49f393ce5c6f0;hb=485f66f1744fea056e20a5bef619989bf1749202;hp=655d7564a7dbdc385e4f15a06ee04a9e88682296;hpb=faf9337f27516c18ca3e406401d68b361c890622;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ForkController.php b/includes/ForkController.php index 655d7564a7..cc16964e1f 100644 --- a/includes/ForkController.php +++ b/includes/ForkController.php @@ -19,6 +19,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * Class for managing forking command line scripts. @@ -53,7 +54,7 @@ class ForkController { 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; @@ -133,8 +134,7 @@ class ForkController { $this->termReceived = false; } } while ( count( $this->children ) ); - - $this->initProcess(); + pcntl_signal( SIGTERM, SIG_DFL ); return 'done'; } @@ -150,12 +150,14 @@ class ForkController { 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; } /** @@ -177,7 +179,7 @@ class ForkController { } if ( !$pid ) { - $this->initProcess(); + $this->initChild(); $this->childNumber = $i; return 'child'; } else { @@ -189,10 +191,9 @@ class ForkController { 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 ); }