MediaWiki  1.23.8
Go to the documentation of this file.
1 <?php
46  function __construct( $params ) {
49  if ( $params['persistent'] ) {
50  // The pool ID must be unique to the server/option combination.
51  // The Memcached object is essentially shared for each pool ID.
52  // We can only reuse a pool ID if we keep the config consistent.
53  $this->client = new Memcached( md5( serialize( $params ) ) );
54  if ( count( $this->client->getServerList() ) ) {
55  wfDebug( __METHOD__ . ": persistent Memcached object already loaded.\n" );
56  return; // already initialized; don't add duplicate servers
57  }
58  } else {
59  $this->client = new Memcached;
60  }
62  if ( !isset( $params['serializer'] ) ) {
63  $params['serializer'] = 'php';
64  }
66  if ( isset( $params['retry_timeout'] ) ) {
67  $this->client->setOption( Memcached::OPT_RETRY_TIMEOUT, $params['retry_timeout'] );
68  }
70  if ( isset( $params['server_failure_limit'] ) ) {
71  $this->client->setOption( Memcached::OPT_SERVER_FAILURE_LIMIT, $params['server_failure_limit'] );
72  }
74  // The compression threshold is an undocumented php.ini option for some
75  // reason. There's probably not much harm in setting it globally, for
76  // compatibility with the settings for the PHP client.
77  ini_set( 'memcached.compression_threshold', $params['compress_threshold'] );
79  // Set timeouts
80  $this->client->setOption( Memcached::OPT_CONNECT_TIMEOUT, $params['connect_timeout'] * 1000 );
81  $this->client->setOption( Memcached::OPT_SEND_TIMEOUT, $params['timeout'] );
82  $this->client->setOption( Memcached::OPT_RECV_TIMEOUT, $params['timeout'] );
83  $this->client->setOption( Memcached::OPT_POLL_TIMEOUT, $params['timeout'] / 1000 );
85  // Set libketama mode since it's recommended by the documentation and
86  // is as good as any. There's no way to configure libmemcached to use
87  // hashes identical to the ones currently in use by the PHP client, and
88  // even implementing one of the libmemcached hashes in pure PHP for
89  // forwards compatibility would require MWMemcached::get_sock() to be
90  // rewritten.
91  $this->client->setOption( Memcached::OPT_LIBKETAMA_COMPATIBLE, true );
93  // Set the serializer
94  switch ( $params['serializer'] ) {
95  case 'php':
96  $this->client->setOption( Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP );
97  break;
98  case 'igbinary':
99  if ( !Memcached::HAVE_IGBINARY ) {
100  throw new MWException( __CLASS__ . ': the igbinary extension is not available ' .
101  'but igbinary serialization was requested.' );
102  }
103  $this->client->setOption( Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY );
104  break;
105  default:
106  throw new MWException( __CLASS__ . ': invalid value for serializer parameter' );
107  }
108  $servers = array();
109  foreach ( $params['servers'] as $host ) {
110  $servers[] = IP::splitHostAndPort( $host ); // (ip, port)
111  }
112  $this->client->addServers( $servers );
113  }
120  public function get( $key, &$casToken = null ) {
121  wfProfileIn( __METHOD__ );
122  $this->debugLog( "get($key)" );
123  $result = $this->client->get( $this->encodeKey( $key ), null, $casToken );
124  $result = $this->checkResult( $key, $result );
125  wfProfileOut( __METHOD__ );
126  return $result;
127  }
135  public function set( $key, $value, $exptime = 0 ) {
136  $this->debugLog( "set($key)" );
137  return $this->checkResult( $key, parent::set( $key, $value, $exptime ) );
138  }
147  public function cas( $casToken, $key, $value, $exptime = 0 ) {
148  $this->debugLog( "cas($key)" );
149  return $this->checkResult( $key, parent::cas( $casToken, $key, $value, $exptime ) );
150  }
157  public function delete( $key, $time = 0 ) {
158  $this->debugLog( "delete($key)" );
159  $result = parent::delete( $key, $time );
160  if ( $result === false && $this->client->getResultCode() === Memcached::RES_NOTFOUND ) {
161  // "Not found" is counted as success in our interface
162  return true;
163  } else {
164  return $this->checkResult( $key, $result );
165  }
166  }
174  public function add( $key, $value, $exptime = 0 ) {
175  $this->debugLog( "add($key)" );
176  return $this->checkResult( $key, parent::add( $key, $value, $exptime ) );
177  }
184  public function incr( $key, $value = 1 ) {
185  $this->debugLog( "incr($key)" );
186  $result = $this->client->increment( $key, $value );
187  return $this->checkResult( $key, $result );
188  }
195  public function decr( $key, $value = 1 ) {
196  $this->debugLog( "decr($key)" );
197  $result = $this->client->decrement( $key, $value );
198  return $this->checkResult( $key, $result );
199  }
212  protected function checkResult( $key, $result ) {
213  if ( $result !== false ) {
214  return $result;
215  }
216  switch ( $this->client->getResultCode() ) {
217  case Memcached::RES_SUCCESS:
218  break;
219  case Memcached::RES_DATA_EXISTS:
220  case Memcached::RES_NOTSTORED:
221  case Memcached::RES_NOTFOUND:
222  $this->debugLog( "result: " . $this->client->getResultMessage() );
223  break;
224  default:
225  $msg = $this->client->getResultMessage();
226  if ( $key !== false ) {
227  $server = $this->client->getServerByKey( $key );
228  $serverName = "{$server['host']}:{$server['port']}";
229  $msg = "Memcached error for key \"$key\" on server \"$serverName\": $msg";
230  } else {
231  $msg = "Memcached error: $msg";
232  }
233  wfDebugLog( 'memcached-serious', $msg );
235  }
236  return $result;
237  }
243  public function getMulti( array $keys ) {
244  wfProfileIn( __METHOD__ );
245  $this->debugLog( 'getMulti(' . implode( ', ', $keys ) . ')' );
246  $callback = array( $this, 'encodeKey' );
247  $result = $this->client->getMulti( array_map( $callback, $keys ) );
248  wfProfileOut( __METHOD__ );
249  return $this->checkResult( false, $result );
250  }
252  /* NOTE: there is no cas() method here because it is currently not supported
253  * by the BagOStuff interface and other BagOStuff subclasses, such as
254  * SqlBagOStuff.
255  */
256 }
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
Definition: hooks.txt:1528
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
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
Definition: skin.txt:62
Base class for memcached clients.
Definition: MemcachedBagOStuff.php:29
applyDefaultParams( $params)
Fill in the defaults for any parameters missing from $params, using the backwards-compatible global v...
Definition: MemcachedBagOStuff.php:36
__construct( $params)
Definition: MemcachedPeclBagOStuff.php:46
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
Definition: styleTest.css.php:40
checkResult( $key, $result)
Check the return value from a client method call and take any necessary action.
Definition: MemcachedPeclBagOStuff.php:212
debugLog( $text)
Send a debug message to the log.
Definition: MemcachedBagOStuff.php:170
add( $key, $value, $exptime=0)
Definition: MemcachedPeclBagOStuff.php:174
MediaWiki exception.
Definition: MWException.php:26
getMulti(array $keys)
Definition: MemcachedPeclBagOStuff.php:243
incr( $key, $value=1)
Definition: MemcachedPeclBagOStuff.php:184
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
An extension or a will often add custom code to the function with or without a global variable For someone wanting email notification when an article is shown may add
Definition: hooks.txt:51
encodeKey( $key)
Encode a key for use on the wire inside the memcached protocol.
Definition: MemcachedBagOStuff.php:128
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
Definition: styleTest.css.php:45
static splitHostAndPort( $both)
Given a host/port string, like one might find in the host part of a URL per RFC 2732,...
Definition: IP.php:240
cas( $casToken, $key, $value, $exptime=0)
Definition: MemcachedPeclBagOStuff.php:147
it s the revision text itself In either if gzip is set
Definition: hooks.txt:2113
A wrapper class for the PECL memcached client.
Definition: MemcachedPeclBagOStuff.php:29
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
Definition: distributors.txt:9
Definition: testCompression.php:63
setLastError( $err)
Set the "last error" registry.
Definition: BagOStuff.php:332
Definition: BagOStuff.php:52
decr( $key, $value=1)
Definition: MemcachedPeclBagOStuff.php:195