57 if ( PHP_SAPI !=
'cli' ) {
58 throw new MWException(
"ForkController cannot be used from the web." );
60 $this->procsToStart = $numProcs;
77 pcntl_signal( SIGTERM, [ $this,
'handleTermSignal' ],
false );
81 if ( $this->procsToStart ) {
82 if ( $this->
forkWorkers( $this->procsToStart ) ==
'child' ) {
85 $this->procsToStart = 0;
90 $deadPid = pcntl_wait(
$status );
94 unset( $this->children[$deadPid] );
95 if ( $this->
flags & self::RESTART_ON_ERROR ) {
96 if ( pcntl_wifsignaled(
$status ) ) {
99 $signal = pcntl_wtermsig(
$status );
100 if ( in_array( $signal, self::$restartableSignals ) ) {
101 echo
"Worker exited with signal $signal, restarting\n";
102 $this->procsToStart++;
104 } elseif ( pcntl_wifexited(
$status ) ) {
106 $exitStatus = pcntl_wexitstatus(
$status );
107 if ( $exitStatus != 0 ) {
108 echo
"Worker exited with status $exitStatus, restarting\n";
109 $this->procsToStart++;
111 echo
"Worker exited normally\n";
116 if ( $this->procsToStart ) {
122 if ( function_exists(
'pcntl_signal_dispatch' ) ) {
123 pcntl_signal_dispatch();
125 declare( ticks = 1 ) {
130 if ( $this->termReceived ) {
131 foreach ( $this->children
as $childPid => $unused ) {
132 posix_kill( $childPid, SIGTERM );
134 $this->termReceived =
false;
136 }
while ( count( $this->children ) );
137 pcntl_signal( SIGTERM, SIG_DFL );
154 MediaWikiServices::resetChildProcessServices();
173 for ( $i = 0; $i < $numProcs; $i++ ) {
176 if ( $pid === -1 || $pid ===
false ) {
177 echo
"Error creating child processes\n";
183 $this->childNumber = $i;
187 $this->children[$pid] =
true;
197 $this->children = null;
198 pcntl_signal( SIGTERM, SIG_DFL );
202 $this->termReceived =
true;
forkWorkers($numProcs)
Fork a number of worker processes.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
const RESTART_ON_ERROR
Pass this flag to __construct() to cause the class to automatically restart workers that exit with no...
static destroySingletons()
Destroy all singleton() instances.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
when a variable name is used in a it is silently declared as a new local masking the global
static destroySingleton()
Destroy the singleton instance.
__construct($numProcs, $flags=0)
start()
Start the child processes.
wfGetCache($cacheType)
Get a specific cache object.
Class for managing forking command line scripts.
static destroySingletons()
Destroy the singleton instances.
CACHE_MEMCACHED $wgMainCacheType
getChildNumber()
Get the number of the child currently running.
handleTermSignal($signal)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static $restartableSignals
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
static clear()
Clear all the cached instances.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database etc For and for historical it also represents a few features of articles that don t involve their such as access rights See also title txt Article Encapsulates access to the page table of the database The object represents a an and maintains state such as flags
static destroySingletons()
Destroy the singleton instances.