MediaWiki master
MediaWiki\Maintenance\ForkController Class Reference

Manage forking inside CLI maintenance scripts. More...

Inherited by MediaWiki\Composer\ComposerLaunchParallel, and MediaWiki\Maintenance\OrderedStreamingForkController.

Public Member Functions

 __construct ( $numProcs, $flags=0)
 
 allSuccessful ()
 Return true if all completed child processes exited with an exit status / return code of 0.
 
 getChildNumber ()
 Get the number of the child currently running.
 
 start ()
 Start the child processes.
 

Protected Member Functions

 forkWorkers ( $numProcs)
 Fork a number of worker processes.
 
 handleTermSignal ( $signal)
 
 initChild ()
 
 prepareEnvironment ()
 

Protected Attributes

int $childNumber = 0
 
array null $children = []
 
int[] $exitStatuses = []
 
int $flags = 0
 
int $procsToStart = 0
 
bool $termReceived = false
 

Static Protected Attributes

static int[] $RESTARTABLE_SIGNALS = []
 

Detailed Description

Manage forking inside CLI maintenance scripts.

Only handles forking and process control. In the future, this could be extended to provide IPC and job dispatch.

This class requires the posix and pcntl extensions.

Definition at line 37 of file ForkController.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Maintenance\ForkController::__construct ( $numProcs,
$flags = 0 )
Parameters
int$numProcsThe number of worker processes to fork
int$flags

Definition at line 69 of file ForkController.php.

References MediaWiki\Maintenance\ForkController\$flags, and wfIsCLI().

Member Function Documentation

◆ allSuccessful()

MediaWiki\Maintenance\ForkController::allSuccessful ( )

Return true if all completed child processes exited with an exit status / return code of 0.

Returns
bool

Definition at line 183 of file ForkController.php.

◆ forkWorkers()

MediaWiki\Maintenance\ForkController::forkWorkers ( $numProcs)
protected

Fork a number of worker processes.

Parameters
int$numProcs
Returns
string

Reimplemented in MediaWiki\Maintenance\OrderedStreamingForkController.

Definition at line 214 of file ForkController.php.

Referenced by MediaWiki\Maintenance\ForkController\start().

◆ getChildNumber()

MediaWiki\Maintenance\ForkController::getChildNumber ( )

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

Returns
int

Definition at line 197 of file ForkController.php.

◆ handleTermSignal()

MediaWiki\Maintenance\ForkController::handleTermSignal ( $signal)
protected

Definition at line 244 of file ForkController.php.

◆ initChild()

MediaWiki\Maintenance\ForkController::initChild ( )
protected

◆ prepareEnvironment()

MediaWiki\Maintenance\ForkController::prepareEnvironment ( )
protected

◆ start()

MediaWiki\Maintenance\ForkController::start ( )

Start the child processes.

This should only be called from the command line. It should be called as early as possible during execution.

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'.

Returns
string

Reimplemented in MediaWiki\Composer\ComposerLaunchParallel, and MediaWiki\Maintenance\OrderedStreamingForkController.

Definition at line 103 of file ForkController.php.

References MediaWiki\Maintenance\ForkController\forkWorkers().

Member Data Documentation

◆ $childNumber

int MediaWiki\Maintenance\ForkController::$childNumber = 0
protected

Definition at line 42 of file ForkController.php.

◆ $children

array null MediaWiki\Maintenance\ForkController::$children = []
protected

Definition at line 39 of file ForkController.php.

◆ $exitStatuses

int [] MediaWiki\Maintenance\ForkController::$exitStatuses = []
protected

Definition at line 57 of file ForkController.php.

◆ $flags

int MediaWiki\Maintenance\ForkController::$flags = 0
protected

Definition at line 48 of file ForkController.php.

Referenced by MediaWiki\Maintenance\ForkController\__construct().

◆ $procsToStart

int MediaWiki\Maintenance\ForkController::$procsToStart = 0
protected

Definition at line 51 of file ForkController.php.

◆ $RESTARTABLE_SIGNALS

int [] MediaWiki\Maintenance\ForkController::$RESTARTABLE_SIGNALS = []
staticprotected

Definition at line 54 of file ForkController.php.

◆ $termReceived

bool MediaWiki\Maintenance\ForkController::$termReceived = false
protected

Definition at line 45 of file ForkController.php.


The documentation for this class was generated from the following file: