MediaWiki  master
ForkController Class Reference

Class for managing forking command line scripts. More...

Inheritance diagram for ForkController:

Public Member Functions

 __construct ( $numProcs, $flags=0)
 
 getChildNumber ()
 Get the number of the child currently running. More...
 
 start ()
 Start the child processes. More...
 

Protected Member Functions

 forkWorkers ( $numProcs)
 Fork a number of worker processes. More...
 
 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

Class for managing forking command line scripts.

Currently just does forking and process control, but it could easily be extended to provide IPC and job dispatch.

This class requires the posix and pcntl extensions.

Definition at line 33 of file ForkController.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 61 of file ForkController.php.

References $flags, and wfIsCLI().

Member Function Documentation

◆ forkWorkers()

ForkController::forkWorkers (   $numProcs)
protected

Fork a number of worker processes.

Parameters
int$numProcs
Returns
string

Reimplemented in OrderedStreamingForkController.

Definition at line 180 of file ForkController.php.

References initChild(), and prepareEnvironment().

Referenced by start().

◆ getChildNumber()

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

References $childNumber.

◆ handleTermSignal()

ForkController::handleTermSignal (   $signal)
protected

Definition at line 210 of file ForkController.php.

◆ initChild()

ForkController::initChild ( )
protected

Definition at line 205 of file ForkController.php.

Referenced by forkWorkers(), and OrderedStreamingForkController\forkWorkers().

◆ prepareEnvironment()

ForkController::prepareEnvironment ( )
protected

◆ start()

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

Definition at line 90 of file ForkController.php.

References forkWorkers().

Member Data Documentation

◆ $childNumber

int ForkController::$childNumber = 0
protected

Definition at line 38 of file ForkController.php.

Referenced by getChildNumber().

◆ $children

array null ForkController::$children = []
protected

Definition at line 35 of file ForkController.php.

◆ $flags

int ForkController::$flags = 0
protected

Definition at line 44 of file ForkController.php.

Referenced by __construct().

◆ $procsToStart

int ForkController::$procsToStart = 0
protected

Definition at line 47 of file ForkController.php.

◆ $RESTARTABLE_SIGNALS

ForkController::$RESTARTABLE_SIGNALS = []
staticprotected

Definition at line 49 of file ForkController.php.

◆ $termReceived

bool ForkController::$termReceived = false
protected

Definition at line 41 of file ForkController.php.


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