*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* Class for managing forking command line scripts.
* @ingroup Maintenance
*/
class ForkController {
- protected $children = array();
+ protected $children = [], $childNumber = 0;
protected $termReceived = false;
protected $flags = 0, $procsToStart = 0;
- protected static $restartableSignals = array(
+ protected static $restartableSignals = [
SIGFPE,
SIGILL,
SIGSEGV,
SIGPIPE,
SIGXCPU,
SIGXFSZ,
- );
+ ];
/**
* Pass this flag to __construct() to cause the class to automatically restart
*/
public function start() {
// Trap SIGTERM
- pcntl_signal( SIGTERM, array( $this, 'handleTermSignal' ), false );
+ pcntl_signal( SIGTERM, [ $this, 'handleTermSignal' ], false );
do {
// Start child processes
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 $wgMemc;
// Don't share DB, storage, or memcached connections
- wfGetLBFactory()->destroyInstance();
+ 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 ) {
if ( !$pid ) {
$this->initChild();
+ $this->childNumber = $i;
return 'child';
} else {
// This is the parent process