MediaWiki REL1_33
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.
 
 start ()
 Start the child processes.
 

Public Attributes

const RESTART_ON_ERROR = 1
 Pass this flag to __construct() to cause the class to automatically restart workers that exit with non-zero exit status or a signal such as SIGSEGV.
 

Protected Member Functions

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

Protected Attributes

 $childNumber = 0
 
 $children = []
 
 $flags = 0
 
 $procsToStart = 0
 
 $termReceived = false
 

Static Protected Attributes

static $restartableSignals
 

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 )

Definition at line 56 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 169 of file ForkController.php.

References and(), 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 147 of file ForkController.php.

References $childNumber.

◆ handleTermSignal()

ForkController::handleTermSignal ( $signal)
protected

Definition at line 201 of file ForkController.php.

◆ initChild()

ForkController::initChild ( )
protected

Definition at line 194 of file ForkController.php.

References $wgMemc, and(), and wfGetCache().

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

◆ prepareEnvironment()

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

References and(), and forkWorkers().

Member Data Documentation

◆ $childNumber

ForkController::$childNumber = 0
protected

Definition at line 34 of file ForkController.php.

Referenced by getChildNumber().

◆ $children

ForkController::$children = []
protected

Definition at line 34 of file ForkController.php.

◆ $flags

ForkController::$flags = 0
protected

Definition at line 36 of file ForkController.php.

Referenced by __construct().

◆ $procsToStart

ForkController::$procsToStart = 0
protected

Definition at line 36 of file ForkController.php.

◆ $restartableSignals

ForkController::$restartableSignals
staticprotected
Initial value:
= [
]
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy

Definition at line 38 of file ForkController.php.

◆ $termReceived

ForkController::$termReceived = false
protected

Definition at line 35 of file ForkController.php.

◆ RESTART_ON_ERROR

const ForkController::RESTART_ON_ERROR = 1

Pass this flag to __construct() to cause the class to automatically restart workers that exit with non-zero exit status or a signal such as SIGSEGV.

Definition at line 54 of file ForkController.php.


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