MediaWiki REL1_40
MediaWiki\Maintenance\ForkController Class Reference

Manage forking inside CLI maintenance scripts. More...

Inherited by MediaWiki\Maintenance\OrderedStreamingForkController.

Public Member Functions

 __construct ( $numProcs, $flags=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 $flags = 0
 
int $procsToStart = 0
 
bool $termReceived = false
 

Static Protected Attributes

static $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 38 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 66 of file ForkController.php.

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

Member Function Documentation

◆ 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 189 of file ForkController.php.

References MediaWiki\Maintenance\ForkController\initChild(), and MediaWiki\Maintenance\ForkController\prepareEnvironment().

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 172 of file ForkController.php.

References MediaWiki\Maintenance\ForkController\$childNumber.

◆ handleTermSignal()

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

Definition at line 219 of file ForkController.php.

◆ initChild()

MediaWiki\Maintenance\ForkController::initChild ( )
protected

◆ prepareEnvironment()

◆ 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\Maintenance\OrderedStreamingForkController.

Definition at line 99 of file ForkController.php.

References MediaWiki\Maintenance\ForkController\forkWorkers().

Member Data Documentation

◆ $childNumber

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

◆ $children

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

Definition at line 40 of file ForkController.php.

◆ $flags

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

Definition at line 49 of file ForkController.php.

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

◆ $procsToStart

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

Definition at line 52 of file ForkController.php.

◆ $RESTARTABLE_SIGNALS

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 46 of file ForkController.php.


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