Go to the documentation of this file.
74 if ( !class_exists(
'Redis' ) ) {
75 throw new MWException( __CLASS__ .
' requires a Redis client library. ' .
76 'See https://www.mediawiki.org/wiki/Redis#Setup' );
78 $this->connectTimeout =
$options[
'connectTimeout'];
79 $this->persistent =
$options[
'persistent'];
80 $this->password =
$options[
'password'];
81 if ( !isset(
$options[
'serializer'] ) ||
$options[
'serializer'] ===
'php' ) {
82 $this->serializer = Redis::SERIALIZER_PHP;
83 } elseif (
$options[
'serializer'] ===
'igbinary' ) {
84 $this->serializer = Redis::SERIALIZER_IGBINARY;
85 } elseif (
$options[
'serializer'] ===
'none' ) {
86 $this->serializer = Redis::SERIALIZER_NONE;
88 throw new MWException(
"Invalid serializer specified." );
97 if ( !isset(
$options[
'connectTimeout'] ) ) {
100 if ( !isset(
$options[
'persistent'] ) ) {
103 if ( !isset(
$options[
'password'] ) ) {
126 $id = sha1( serialize(
$options ) );
128 if ( !isset( self::$instances[$id] ) ) {
129 self::$instances[$id] =
new self(
$options );
130 wfDebug(
"Creating a new " . __CLASS__ .
" instance with id $id.\n" );
133 return self::$instances[$id];
148 if ( isset( $this->downServers[$server] ) ) {
150 if ( $now > $this->downServers[$server] ) {
152 unset( $this->downServers[$server] );
155 wfDebug(
"server $server is marked down for another " .
156 ( $this->downServers[$server] - $now ) .
" seconds, can't get connection\n" );
163 if ( isset( $this->connections[$server] ) ) {
164 foreach ( $this->connections[$server]
as &$connection ) {
165 if ( $connection[
'free'] ) {
166 $connection[
'free'] =
false;
169 return new RedisConnRef( $this, $server, $connection[
'conn'] );
174 if ( substr( $server, 0, 1 ) ===
'/' ) {
184 throw new MWException( __CLASS__ .
": invalid configured server \"$server\"" );
186 list( $host, $port ) = $hostPort;
187 if ( $port ===
false ) {
194 if ( $this->persistent ) {
195 $result = $conn->pconnect( $host, $port, $this->connectTimeout );
197 $result = $conn->connect( $host, $port, $this->connectTimeout );
200 wfDebugLog(
'redis',
"Could not connect to server $server" );
206 if ( $this->password !==
null ) {
207 if ( !$conn->auth( $this->password ) ) {
208 wfDebugLog(
'redis',
"Authentication error connecting to $server" );
211 }
catch ( RedisException
$e ) {
213 wfDebugLog(
'redis',
"Redis exception connecting to $server: " .
$e->getMessage() );
219 $conn->setOption( Redis::OPT_SERIALIZER, $this->serializer );
220 $this->connections[$server][] =
array(
'conn' => $conn,
'free' =>
false );
238 foreach ( $this->connections[$server]
as &$connection ) {
239 if ( $connection[
'conn'] === $conn && !$connection[
'free'] ) {
240 $connection[
'free'] =
true;
255 if ( $this->idlePoolSize <= count( $this->connections ) ) {
259 foreach ( $this->connections
as &$serverConnections ) {
260 foreach ( $serverConnections
as $key => &$connection ) {
261 if ( $connection[
'free'] ) {
262 unset( $serverConnections[$key] );
263 if ( --$this->idlePoolSize <= count( $this->connections ) ) {
297 wfDebugLog(
'redis',
"Redis exception on server $server: " .
$e->getMessage() .
"\n" );
298 foreach ( $this->connections[$server]
as $key => $connection ) {
300 $this->idlePoolSize -= $connection[
'free'] ? 1 : 0;
301 unset( $this->connections[$server][$key] );
324 if ( $this->password !==
null ) {
325 if ( !$conn->auth( $this->password ) ) {
326 wfDebugLog(
'redis',
"Authentication error connecting to $server" );
339 foreach ( $this->connections
as $server => &$serverConnections ) {
340 foreach ( $serverConnections
as $key => &$connection ) {
341 $connection[
'conn']->close();
388 $this->lastError =
null;
394 $conn->clearLastError();
396 if ( preg_match(
'/^ERR operation not permitted\b/',
$conn->getLastError() ) ) {
397 $this->pool->reauthenticateConnection( $this->
server, $conn );
398 $conn->clearLastError();
400 wfDebugLog(
'redis',
"Used automatic re-authentication for method '$name'." );
416 $sha1 = sha1( $script );
421 $conn->clearLastError();
427 if ( preg_match(
'/^ERR operation not permitted\b/',
$conn->getLastError() ) ) {
428 $this->pool->reauthenticateConnection(
$server,
$conn );
429 $conn->clearLastError();
431 wfDebugLog(
'redis',
"Used automatic re-authentication for Lua script $sha1." );
434 if ( preg_match(
'/^NOSCRIPT/',
$conn->getLastError() ) ) {
435 $conn->clearLastError();
437 wfDebugLog(
'redis',
"Used eval() for Lua script $sha1." );
440 if (
$conn->getLastError() ) {
441 wfDebugLog(
'redis',
"Lua script error on server $server: " .
$conn->getLastError() );
454 return $this->conn ===
$conn;
458 $this->pool->freeConnection( $this->
server, $this->conn );
freeConnection( $server, Redis $conn)
Mark a connection to a server as free to return to the pool.
const SERVER_DOWN_TTL
integer; seconds to cache servers as "down".
array $downServers
(server name => UNIX timestamp) *
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
static singleton(array $options)
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
__construct(array $options)
array $connections
(server name => ((connection info array),...) *
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
handleError(RedisConnRef $cref, RedisException $e)
The redis extension throws an exception in response to various read, write and protocol errors.
__call( $name, $arguments)
isConnIdentical(Redis $conn)
closeExcessIdleConections()
Close any extra idle connections if there are more than the limit.
handleException( $server, RedisConnRef $cref, RedisException $e)
The redis extension throws an exception in response to various read, write and protocol errors.
getConnection( $server)
Get a connection to a redis server.
string $password
Plaintext auth password *.
int $serializer
Serializer to use (Redis::SERIALIZER_*) *.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
static applyDefaultConfig(array $options)
RedisConnectionPool $pool
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
__construct(RedisConnectionPool $pool, $server, Redis $conn)
int $idlePoolSize
Current idle pool size *.
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Helper class to manage Redis connections.
Allows to change the fields on the form that will be generated $name
static splitHostAndPort( $both)
Given a host/port string, like one might find in the host part of a URL per RFC 2732,...
reauthenticateConnection( $server, Redis $conn)
Re-send an AUTH request to the redis server (useful after disconnects).
luaEval( $script, array $params, $numKeys)
string $connectTimeout
Connection timeout in seconds *.
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
Helper class to handle automatically marking connectons as reusable (via RAII pattern)
bool $persistent
Whether connections persist *.
__destruct()
Make sure connections are closed for sanity.
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is it should be possible to enable the appropriate rewrite rules by if you can reconfigure the web server