MediaWiki  1.23.14
MemcachedClient.php
Go to the documentation of this file.
1 <?php
66 // {{{ requirements
67 // }}}
68 
69 // {{{ class MWMemcached
76 class MWMemcached {
77  // {{{ properties
78  // {{{ public
79 
80  // {{{ constants
81  // {{{ flags
82 
86  const SERIALIZED = 1;
87 
91  const COMPRESSED = 2;
92 
93  // }}}
94 
98  const COMPRESSION_SAVINGS = 0.20;
99 
100  // }}}
101 
108  var $stats;
109 
110  // }}}
111  // {{{ private
112 
119  var $_cache_sock;
120 
127  var $_debug;
128 
135  var $_host_dead;
136 
143  var $_have_zlib;
144 
151  var $_compress_enable;
152 
160 
167  var $_persistent;
168 
175  var $_single_sock;
176 
183  var $_servers;
184 
191  var $_buckets;
192 
199  var $_bucketcount;
200 
207  var $_active;
208 
215  var $_timeout_seconds;
216 
224 
228  var $_connect_timeout;
229 
234 
235  // }}}
236  // }}}
237  // {{{ methods
238  // {{{ public functions
239  // {{{ memcached()
240 
248  public function __construct( $args ) {
249  $this->set_servers( isset( $args['servers'] ) ? $args['servers'] : array() );
250  $this->_debug = isset( $args['debug'] ) ? $args['debug'] : false;
251  $this->stats = array();
252  $this->_compress_threshold = isset( $args['compress_threshold'] ) ? $args['compress_threshold'] : 0;
253  $this->_persistent = isset( $args['persistent'] ) ? $args['persistent'] : false;
254  $this->_compress_enable = true;
255  $this->_have_zlib = function_exists( 'gzcompress' );
256 
257  $this->_cache_sock = array();
258  $this->_host_dead = array();
259 
260  $this->_timeout_seconds = 0;
261  $this->_timeout_microseconds = isset( $args['timeout'] ) ? $args['timeout'] : 500000;
262 
263  $this->_connect_timeout = isset( $args['connect_timeout'] ) ? $args['connect_timeout'] : 0.1;
264  $this->_connect_attempts = 2;
265  }
266 
267  // }}}
268  // {{{ add()
269 
284  public function add( $key, $val, $exp = 0 ) {
285  return $this->_set( 'add', $key, $val, $exp );
286  }
287 
288  // }}}
289  // {{{ decr()
290 
299  public function decr( $key, $amt = 1 ) {
300  return $this->_incrdecr( 'decr', $key, $amt );
301  }
302 
303  // }}}
304  // {{{ delete()
305 
314  public function delete( $key, $time = 0 ) {
315  if ( !$this->_active ) {
316  return false;
317  }
318 
319  $sock = $this->get_sock( $key );
320  if ( !is_resource( $sock ) ) {
321  return false;
322  }
323 
324  $key = is_array( $key ) ? $key[1] : $key;
325 
326  if ( isset( $this->stats['delete'] ) ) {
327  $this->stats['delete']++;
328  } else {
329  $this->stats['delete'] = 1;
330  }
331  $cmd = "delete $key $time\r\n";
332  if ( !$this->_fwrite( $sock, $cmd ) ) {
333  return false;
334  }
335  $res = $this->_fgets( $sock );
336 
337  if ( $this->_debug ) {
338  $this->_debugprint( sprintf( "MemCache: delete %s (%s)\n", $key, $res ) );
339  }
340 
341  if ( $res == "DELETED" || $res == "NOT_FOUND" ) {
342  return true;
343  }
344 
345  return false;
346  }
347 
353  public function lock( $key, $timeout = 0 ) {
354  /* stub */
355  return true;
356  }
357 
362  public function unlock( $key ) {
363  /* stub */
364  return true;
365  }
366 
367  // }}}
368  // {{{ disconnect_all()
369 
373  public function disconnect_all() {
374  foreach ( $this->_cache_sock as $sock ) {
375  fclose( $sock );
376  }
377 
378  $this->_cache_sock = array();
379  }
380 
381  // }}}
382  // {{{ enable_compress()
383 
389  public function enable_compress( $enable ) {
390  $this->_compress_enable = $enable;
391  }
392 
393  // }}}
394  // {{{ forget_dead_hosts()
395 
399  public function forget_dead_hosts() {
400  $this->_host_dead = array();
401  }
402 
403  // }}}
404  // {{{ get()
405 
414  public function get( $key, &$casToken = null ) {
415  wfProfileIn( __METHOD__ );
416 
417  if ( $this->_debug ) {
418  $this->_debugprint( "get($key)\n" );
419  }
420 
421  if ( !$this->_active ) {
422  wfProfileOut( __METHOD__ );
423  return false;
424  }
425 
426  $sock = $this->get_sock( $key );
427 
428  if ( !is_resource( $sock ) ) {
429  wfProfileOut( __METHOD__ );
430  return false;
431  }
432 
433  $key = is_array( $key ) ? $key[1] : $key;
434  if ( isset( $this->stats['get'] ) ) {
435  $this->stats['get']++;
436  } else {
437  $this->stats['get'] = 1;
438  }
439 
440  $cmd = "gets $key\r\n";
441  if ( !$this->_fwrite( $sock, $cmd ) ) {
442  wfProfileOut( __METHOD__ );
443  return false;
444  }
445 
446  $val = array();
447  $this->_load_items( $sock, $val, $casToken );
448 
449  if ( $this->_debug ) {
450  foreach ( $val as $k => $v ) {
451  $this->_debugprint( sprintf( "MemCache: sock %s got %s\n", serialize( $sock ), $k ) );
452  }
453  }
454 
455  $value = false;
456  if ( isset( $val[$key] ) ) {
457  $value = $val[$key];
458  }
459  wfProfileOut( __METHOD__ );
460  return $value;
461  }
462 
463  // }}}
464  // {{{ get_multi()
465 
473  public function get_multi( $keys ) {
474  if ( !$this->_active ) {
475  return false;
476  }
477 
478  if ( isset( $this->stats['get_multi'] ) ) {
479  $this->stats['get_multi']++;
480  } else {
481  $this->stats['get_multi'] = 1;
482  }
483  $sock_keys = array();
484  $socks = array();
485  foreach ( $keys as $key ) {
486  $sock = $this->get_sock( $key );
487  if ( !is_resource( $sock ) ) {
488  continue;
489  }
490  $key = is_array( $key ) ? $key[1] : $key;
491  if ( !isset( $sock_keys[$sock] ) ) {
492  $sock_keys[intval( $sock )] = array();
493  $socks[] = $sock;
494  }
495  $sock_keys[intval( $sock )][] = $key;
496  }
497 
498  $gather = array();
499  // Send out the requests
500  foreach ( $socks as $sock ) {
501  $cmd = 'gets';
502  foreach ( $sock_keys[intval( $sock )] as $key ) {
503  $cmd .= ' ' . $key;
504  }
505  $cmd .= "\r\n";
506 
507  if ( $this->_fwrite( $sock, $cmd ) ) {
508  $gather[] = $sock;
509  }
510  }
511 
512  // Parse responses
513  $val = array();
514  foreach ( $gather as $sock ) {
515  $this->_load_items( $sock, $val, $casToken );
516  }
517 
518  if ( $this->_debug ) {
519  foreach ( $val as $k => $v ) {
520  $this->_debugprint( sprintf( "MemCache: got %s\n", $k ) );
521  }
522  }
523 
524  return $val;
525  }
526 
527  // }}}
528  // {{{ incr()
529 
540  public function incr( $key, $amt = 1 ) {
541  return $this->_incrdecr( 'incr', $key, $amt );
542  }
543 
544  // }}}
545  // {{{ replace()
546 
560  public function replace( $key, $value, $exp = 0 ) {
561  return $this->_set( 'replace', $key, $value, $exp );
562  }
563 
564  // }}}
565  // {{{ run_command()
566 
576  public function run_command( $sock, $cmd ) {
577  if ( !is_resource( $sock ) ) {
578  return array();
579  }
580 
581  if ( !$this->_fwrite( $sock, $cmd ) ) {
582  return array();
583  }
584 
585  $ret = array();
586  while ( true ) {
587  $res = $this->_fgets( $sock );
588  $ret[] = $res;
589  if ( preg_match( '/^END/', $res ) ) {
590  break;
591  }
592  if ( strlen( $res ) == 0 ) {
593  break;
594  }
595  }
596  return $ret;
597  }
598 
599  // }}}
600  // {{{ set()
601 
616  public function set( $key, $value, $exp = 0 ) {
617  return $this->_set( 'set', $key, $value, $exp );
618  }
619 
620  // }}}
621  // {{{ cas()
622 
638  public function cas( $casToken, $key, $value, $exp = 0 ) {
639  return $this->_set( 'cas', $key, $value, $exp, $casToken );
640  }
641 
642  // }}}
643  // {{{ set_compress_threshold()
644 
650  public function set_compress_threshold( $thresh ) {
651  $this->_compress_threshold = $thresh;
652  }
653 
654  // }}}
655  // {{{ set_debug()
656 
664  public function set_debug( $dbg ) {
665  $this->_debug = $dbg;
666  }
667 
668  // }}}
669  // {{{ set_servers()
670 
678  public function set_servers( $list ) {
679  $this->_servers = $list;
680  $this->_active = count( $list );
681  $this->_buckets = null;
682  $this->_bucketcount = 0;
683 
684  $this->_single_sock = null;
685  if ( $this->_active == 1 ) {
686  $this->_single_sock = $this->_servers[0];
687  }
688  }
689 
696  public function set_timeout( $seconds, $microseconds ) {
697  $this->_timeout_seconds = $seconds;
698  $this->_timeout_microseconds = $microseconds;
699  }
700 
701  // }}}
702  // }}}
703  // {{{ private methods
704  // {{{ _close_sock()
705 
713  function _close_sock( $sock ) {
714  $host = array_search( $sock, $this->_cache_sock );
715  fclose( $this->_cache_sock[$host] );
716  unset( $this->_cache_sock[$host] );
717  }
718 
719  // }}}
720  // {{{ _connect_sock()
721 
731  function _connect_sock( &$sock, $host ) {
732  list( $ip, $port ) = preg_split( '/:(?=\d)/', $host );
733  $sock = false;
734  $timeout = $this->_connect_timeout;
735  $errno = $errstr = null;
736  for ( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) {
738  if ( $this->_persistent == 1 ) {
739  $sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout );
740  } else {
741  $sock = fsockopen( $ip, $port, $errno, $errstr, $timeout );
742  }
744  }
745  if ( !$sock ) {
746  $this->_error_log( "Error connecting to $host: $errstr\n" );
747  $this->_dead_host( $host );
748  return false;
749  }
750 
751  // Initialise timeout
752  stream_set_timeout( $sock, $this->_timeout_seconds, $this->_timeout_microseconds );
753 
754  // If the connection was persistent, flush the read buffer in case there
755  // was a previous incomplete request on this connection
756  if ( $this->_persistent ) {
757  $this->_flush_read_buffer( $sock );
758  }
759  return true;
760  }
761 
762  // }}}
763  // {{{ _dead_sock()
764 
772  function _dead_sock( $sock ) {
773  $host = array_search( $sock, $this->_cache_sock );
774  $this->_dead_host( $host );
775  }
776 
780  function _dead_host( $host ) {
781  $parts = explode( ':', $host );
782  $ip = $parts[0];
783  $this->_host_dead[$ip] = time() + 30 + intval( rand( 0, 10 ) );
784  $this->_host_dead[$host] = $this->_host_dead[$ip];
785  unset( $this->_cache_sock[$host] );
786  }
787 
788  // }}}
789  // {{{ get_sock()
790 
799  function get_sock( $key ) {
800  if ( !$this->_active ) {
801  return false;
802  }
803 
804  if ( $this->_single_sock !== null ) {
805  return $this->sock_to_host( $this->_single_sock );
806  }
807 
808  $hv = is_array( $key ) ? intval( $key[0] ) : $this->_hashfunc( $key );
809  if ( $this->_buckets === null ) {
810  $bu = array();
811  foreach ( $this->_servers as $v ) {
812  if ( is_array( $v ) ) {
813  for ( $i = 0; $i < $v[1]; $i++ ) {
814  $bu[] = $v[0];
815  }
816  } else {
817  $bu[] = $v;
818  }
819  }
820  $this->_buckets = $bu;
821  $this->_bucketcount = count( $bu );
822  }
823 
824  $realkey = is_array( $key ) ? $key[1] : $key;
825  for ( $tries = 0; $tries < 20; $tries++ ) {
826  $host = $this->_buckets[$hv % $this->_bucketcount];
827  $sock = $this->sock_to_host( $host );
828  if ( is_resource( $sock ) ) {
829  return $sock;
830  }
831  $hv = $this->_hashfunc( $hv . $realkey );
832  }
833 
834  return false;
835  }
836 
837  // }}}
838  // {{{ _hashfunc()
839 
848  function _hashfunc( $key ) {
849  # Hash function must be in [0,0x7ffffff]
850  # We take the first 31 bits of the MD5 hash, which unlike the hash
851  # function used in a previous version of this client, works
852  return hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
853  }
854 
855  // }}}
856  // {{{ _incrdecr()
857 
868  function _incrdecr( $cmd, $key, $amt = 1 ) {
869  if ( !$this->_active ) {
870  return null;
871  }
872 
873  $sock = $this->get_sock( $key );
874  if ( !is_resource( $sock ) ) {
875  return null;
876  }
877 
878  $key = is_array( $key ) ? $key[1] : $key;
879  if ( isset( $this->stats[$cmd] ) ) {
880  $this->stats[$cmd]++;
881  } else {
882  $this->stats[$cmd] = 1;
883  }
884  if ( !$this->_fwrite( $sock, "$cmd $key $amt\r\n" ) ) {
885  return null;
886  }
887 
888  $line = $this->_fgets( $sock );
889  $match = array();
890  if ( !preg_match( '/^(\d+)/', $line, $match ) ) {
891  return null;
892  }
893  return $match[1];
894  }
895 
896  // }}}
897  // {{{ _load_items()
898 
909  function _load_items( $sock, &$ret, &$casToken = null ) {
910  $results = array();
911 
912  while ( 1 ) {
913  $decl = $this->_fgets( $sock );
914 
915  if ( $decl === false ) {
916  /*
917  * If nothing can be read, something is wrong because we know exactly when
918  * to stop reading (right after "END") and we return right after that.
919  */
920  return false;
921  } elseif ( preg_match( '/^VALUE (\S+) (\d+) (\d+) (\d+)$/', $decl, $match ) ) {
922  /*
923  * Read all data returned. This can be either one or multiple values.
924  * Save all that data (in an array) to be processed later: we'll first
925  * want to continue reading until "END" before doing anything else,
926  * to make sure that we don't leave our client in a state where it's
927  * output is not yet fully read.
928  */
929  $results[] = array(
930  $match[1], // rkey
931  $match[2], // flags
932  $match[3], // len
933  $match[4], // casToken
934  $this->_fread( $sock, $match[3] + 2 ), // data
935  );
936  } elseif ( $decl == "END" ) {
937  if ( count( $results ) == 0 ) {
938  return false;
939  }
940 
945  foreach ( $results as $vars ) {
946  list( $rkey, $flags, $len, $casToken, $data ) = $vars;
947 
948  if ( $data === false || substr( $data, -2 ) !== "\r\n" ) {
949  $this->_handle_error( $sock,
950  'line ending missing from data block from $1' );
951  return false;
952  }
953  $data = substr( $data, 0, -2 );
954  $ret[$rkey] = $data;
955 
956  if ( $this->_have_zlib && $flags & self::COMPRESSED ) {
957  $ret[$rkey] = gzuncompress( $ret[$rkey] );
958  }
959 
960  /*
961  * This unserialize is the exact reason that we only want to
962  * process data after having read until "END" (instead of doing
963  * this right away): "unserialize" can trigger outside code:
964  * in the event that $ret[$rkey] is a serialized object,
965  * unserializing it will trigger __wakeup() if present. If that
966  * function attempted to read from memcached (while we did not
967  * yet read "END"), these 2 calls would collide.
968  */
969  if ( $flags & self::SERIALIZED ) {
970  $ret[$rkey] = unserialize( $ret[$rkey] );
971  }
972  }
973 
974  return true;
975  } else {
976  $this->_handle_error( $sock, 'Error parsing response from $1' );
977  return false;
978  }
979  }
980  }
981 
982  // }}}
983  // {{{ _set()
984 
1001  function _set( $cmd, $key, $val, $exp, $casToken = null ) {
1002  if ( !$this->_active ) {
1003  return false;
1004  }
1005 
1006  $sock = $this->get_sock( $key );
1007  if ( !is_resource( $sock ) ) {
1008  return false;
1009  }
1010 
1011  if ( isset( $this->stats[$cmd] ) ) {
1012  $this->stats[$cmd]++;
1013  } else {
1014  $this->stats[$cmd] = 1;
1015  }
1016 
1017  $flags = 0;
1018 
1019  if ( !is_scalar( $val ) ) {
1020  $val = serialize( $val );
1022  if ( $this->_debug ) {
1023  $this->_debugprint( sprintf( "client: serializing data as it is not scalar\n" ) );
1024  }
1025  }
1026 
1027  $len = strlen( $val );
1028 
1029  if ( $this->_have_zlib && $this->_compress_enable
1030  && $this->_compress_threshold && $len >= $this->_compress_threshold
1031  ) {
1032  $c_val = gzcompress( $val, 9 );
1033  $c_len = strlen( $c_val );
1034 
1035  if ( $c_len < $len * ( 1 - self::COMPRESSION_SAVINGS ) ) {
1036  if ( $this->_debug ) {
1037  $this->_debugprint( sprintf( "client: compressing data; was %d bytes is now %d bytes\n", $len, $c_len ) );
1038  }
1039  $val = $c_val;
1040  $len = $c_len;
1042  }
1043  }
1044 
1045  $command = "$cmd $key $flags $exp $len";
1046  if ( $casToken ) {
1047  $command .= " $casToken";
1048  }
1049 
1050  if ( !$this->_fwrite( $sock, "$command\r\n$val\r\n" ) ) {
1051  return false;
1052  }
1053 
1054  $line = $this->_fgets( $sock );
1055 
1056  if ( $this->_debug ) {
1057  $this->_debugprint( sprintf( "%s %s (%s)\n", $cmd, $key, $line ) );
1058  }
1059  if ( $line == "STORED" ) {
1060  return true;
1061  }
1062  return false;
1063  }
1064 
1065  // }}}
1066  // {{{ sock_to_host()
1067 
1076  function sock_to_host( $host ) {
1077  if ( isset( $this->_cache_sock[$host] ) ) {
1078  return $this->_cache_sock[$host];
1079  }
1080 
1081  $sock = null;
1082  $now = time();
1083  list( $ip, /* $port */) = explode( ':', $host );
1084  if ( isset( $this->_host_dead[$host] ) && $this->_host_dead[$host] > $now ||
1085  isset( $this->_host_dead[$ip] ) && $this->_host_dead[$ip] > $now
1086  ) {
1087  return null;
1088  }
1089 
1090  if ( !$this->_connect_sock( $sock, $host ) ) {
1091  return null;
1092  }
1093 
1094  // Do not buffer writes
1095  stream_set_write_buffer( $sock, 0 );
1096 
1097  $this->_cache_sock[$host] = $sock;
1098 
1099  return $this->_cache_sock[$host];
1100  }
1101 
1105  function _debugprint( $text ) {
1106  wfDebugLog( 'memcached', $text );
1107  }
1112  function _error_log( $text ) {
1113  wfDebugLog( 'memcached-serious', "Memcached error: $text" );
1114  }
1115 
1123  function _fwrite( $sock, $buf ) {
1124  $bytesWritten = 0;
1125  $bufSize = strlen( $buf );
1126  while ( $bytesWritten < $bufSize ) {
1127  $result = fwrite( $sock, $buf );
1128  $data = stream_get_meta_data( $sock );
1129  if ( $data['timed_out'] ) {
1130  $this->_handle_error( $sock, 'timeout writing to $1' );
1131  return false;
1132  }
1133  // Contrary to the documentation, fwrite() returns zero on error in PHP 5.3.
1134  if ( $result === false || $result === 0 ) {
1135  $this->_handle_error( $sock, 'error writing to $1' );
1136  return false;
1137  }
1138  $bytesWritten += $result;
1139  }
1140 
1141  return true;
1142  }
1143 
1147  function _handle_error( $sock, $msg ) {
1148  $peer = stream_socket_get_name( $sock, true );
1149  if ( strval( $peer ) === '' ) {
1150  $peer = array_search( $sock, $this->_cache_sock );
1151  if ( $peer === false ) {
1152  $peer = '[unknown host]';
1153  }
1154  }
1155  $msg = str_replace( '$1', $peer, $msg );
1156  $this->_error_log( "$msg\n" );
1157  $this->_dead_sock( $sock );
1158  }
1159 
1168  function _fread( $sock, $len ) {
1169  $buf = '';
1170  while ( $len > 0 ) {
1171  $result = fread( $sock, $len );
1172  $data = stream_get_meta_data( $sock );
1173  if ( $data['timed_out'] ) {
1174  $this->_handle_error( $sock, 'timeout reading from $1' );
1175  return false;
1176  }
1177  if ( $result === false ) {
1178  $this->_handle_error( $sock, 'error reading buffer from $1' );
1179  return false;
1180  }
1181  if ( $result === '' ) {
1182  // This will happen if the remote end of the socket is shut down
1183  $this->_handle_error( $sock, 'unexpected end of file reading from $1' );
1184  return false;
1185  }
1186  $len -= strlen( $result );
1187  $buf .= $result;
1188  }
1189  return $buf;
1190  }
1191 
1199  function _fgets( $sock ) {
1200  $result = fgets( $sock );
1201  // fgets() may return a partial line if there is a select timeout after
1202  // a successful recv(), so we have to check for a timeout even if we
1203  // got a string response.
1204  $data = stream_get_meta_data( $sock );
1205  if ( $data['timed_out'] ) {
1206  $this->_handle_error( $sock, 'timeout reading line from $1' );
1207  return false;
1208  }
1209  if ( $result === false ) {
1210  $this->_handle_error( $sock, 'error reading line from $1' );
1211  return false;
1212  }
1213  if ( substr( $result, -2 ) === "\r\n" ) {
1214  $result = substr( $result, 0, -2 );
1215  } elseif ( substr( $result, -1 ) === "\n" ) {
1216  $result = substr( $result, 0, -1 );
1217  } else {
1218  $this->_handle_error( $sock, 'line ending missing in response from $1' );
1219  return false;
1220  }
1221  return $result;
1222  }
1223 
1228  function _flush_read_buffer( $f ) {
1229  if ( !is_resource( $f ) ) {
1230  return;
1231  }
1232  $r = array( $f );
1233  $w = null;
1234  $e = null;
1235  $n = stream_select( $r, $w, $e, 0, 0 );
1236  while ( $n == 1 && !feof( $f ) ) {
1237  fread( $f, 1024 );
1238  $r = array( $f );
1239  $w = null;
1240  $e = null;
1241  $n = stream_select( $r, $w, $e, 0, 0 );
1242  }
1243  }
1244 
1245  // }}}
1246  // }}}
1247  // }}}
1248 }
1249 
1250 // }}}
1251 
1252 class MemCachedClientforWiki extends MWMemcached {
1253 }
MWMemcached\_dead_sock
_dead_sock( $sock)
Marks a host as dead until 30-40 seconds in the future.
Definition: MemcachedClient.php:757
MWMemcached\$_single_sock
string $_single_sock
If only using one server; contains ip:port to connect to.
Definition: MemcachedClient.php:166
$result
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
MWMemcached\_hashfunc
_hashfunc( $key)
Creates a hash integer based on the $key.
Definition: MemcachedClient.php:833
MWMemcached\$_compress_enable
boolean $_compress_enable
Do we want to use compression?
Definition: MemcachedClient.php:145
MWMemcached\_dead_host
_dead_host( $host)
Definition: MemcachedClient.php:765
php
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
MWMemcached\$_compress_threshold
integer $_compress_threshold
At how many bytes should we compress?
Definition: MemcachedClient.php:152
MWMemcached
This is the PHP client for memcached - a distributed memory cache daemon.
Definition: MemcachedClient.php:76
MWMemcached\COMPRESSION_SAVINGS
const COMPRESSION_SAVINGS
Minimum savings to store data compressed.
Definition: MemcachedClient.php:98
MWMemcached\_set
_set( $cmd, $key, $val, $exp, $casToken=null)
Performs the requested storage operation to the memcache server.
Definition: MemcachedClient.php:986
MWMemcached\get_multi
get_multi( $keys)
Get multiple keys from the server(s)
Definition: MemcachedClient.php:458
MWMemcached\$_connect_timeout
$_connect_timeout
Connect timeout in seconds.
Definition: MemcachedClient.php:213
$f
$f
Definition: UtfNormalTest2.php:38
MWMemcached\$_persistent
boolean $_persistent
Are we using persistent links?
Definition: MemcachedClient.php:159
wfDebugLog
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:1087
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$n
$n
Definition: RandomTest.php:76
$ret
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 noclasses & $ret
Definition: hooks.txt:1530
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2434
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
MWMemcached\$_servers
array $_servers
Array containing ip:port or array(ip:port, weight)
Definition: MemcachedClient.php:173
MWMemcached\_flush_read_buffer
_flush_read_buffer( $f)
Flush the read buffer of a stream.
Definition: MemcachedClient.php:1213
MWMemcached\disconnect_all
disconnect_all()
Disconnects all connected sockets.
Definition: MemcachedClient.php:358
MWMemcached\$_debug
boolean $_debug
Current debug status; 0 - none to 9 - profiling.
Definition: MemcachedClient.php:124
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2124
MWMemcached\COMPRESSED
const COMPRESSED
Flag: indicates data is compressed.
Definition: MemcachedClient.php:91
MWMemcached\_load_items
_load_items( $sock, &$ret, &$casToken=null)
Load items into $ret from $sock.
Definition: MemcachedClient.php:894
MWMemcached\set_servers
set_servers( $list)
Sets the server list to distribute key gets and puts between.
Definition: MemcachedClient.php:663
MWMemcached\_error_log
_error_log( $text)
Definition: MemcachedClient.php:1097
MWMemcached\$_connect_attempts
$_connect_attempts
Number of connection attempts for each server.
Definition: MemcachedClient.php:218
MWMemcached\_fread
_fread( $sock, $len)
Read the specified number of bytes from a stream.
Definition: MemcachedClient.php:1153
MWMemcached\decr
decr( $key, $amt=1)
Decrease a value stored on the memcache server.
Definition: MemcachedClient.php:284
MWMemcached\forget_dead_hosts
forget_dead_hosts()
Forget about all of the dead hosts.
Definition: MemcachedClient.php:384
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2464
MWMemcached\$_host_dead
array $_host_dead
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'.
Definition: MemcachedClient.php:131
MWMemcached\unlock
unlock( $key)
Definition: MemcachedClient.php:347
MWMemcached\$_active
integer $_active
Definition: MemcachedClient.php:194
MWMemcached\$_cache_sock
array $_cache_sock
Cached Sockets that are connected.
Definition: MemcachedClient.php:117
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
MWMemcached\set_debug
set_debug( $dbg)
Sets the debug flag.
Definition: MemcachedClient.php:649
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MWMemcached\set_compress_threshold
set_compress_threshold( $thresh)
Sets the compression threshold.
Definition: MemcachedClient.php:635
MWMemcached\_handle_error
_handle_error( $sock, $msg)
Handle an I/O error.
Definition: MemcachedClient.php:1132
list
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
Definition: deferred.txt:11
MWMemcached\incr
incr( $key, $amt=1)
Increments $key (optionally) by $amt.
Definition: MemcachedClient.php:525
MWMemcached\SERIALIZED
const SERIALIZED
Flag: indicates data is serialized.
Definition: MemcachedClient.php:86
MWMemcached\$_bucketcount
integer $_bucketcount
Total # of bit buckets we have.
Definition: MemcachedClient.php:187
$command
$command
Definition: cdb.php:63
$line
$line
Definition: cdb.php:57
$value
$value
Definition: styleTest.css.php:45
MWMemcached\$_timeout_microseconds
integer $_timeout_microseconds
Stream timeout in microseconds.
Definition: MemcachedClient.php:208
MWMemcached\replace
replace( $key, $value, $exp=0)
Overwrites an existing value for key; only works if key is already set.
Definition: MemcachedClient.php:545
MWMemcached\_connect_sock
_connect_sock(&$sock, $host)
Connects $sock to $host, timing out after $timeout.
Definition: MemcachedClient.php:716
MWMemcached\__construct
__construct( $args)
Memcache initializer.
Definition: MemcachedClient.php:233
MWMemcached\_incrdecr
_incrdecr( $cmd, $key, $amt=1)
Perform increment/decriment on $key.
Definition: MemcachedClient.php:853
MemCachedClientforWiki
Definition: MemcachedClient.php:1237
MWMemcached\$_timeout_seconds
integer $_timeout_seconds
Stream timeout in seconds.
Definition: MemcachedClient.php:201
$args
if( $line===false) $args
Definition: cdb.php:62
MWMemcached\$_buckets
array $_buckets
Our bit buckets.
Definition: MemcachedClient.php:180
MWMemcached\_fwrite
_fwrite( $sock, $buf)
Write to a stream.
Definition: MemcachedClient.php:1108
MWMemcached\get_sock
get_sock( $key)
get_sock
Definition: MemcachedClient.php:784
MWMemcached\$_have_zlib
boolean $_have_zlib
Is compression available?
Definition: MemcachedClient.php:138
MWMemcached\_close_sock
_close_sock( $sock)
Close the specified socket.
Definition: MemcachedClient.php:698
MWMemcached\_fgets
_fgets( $sock)
Read a line from a stream.
Definition: MemcachedClient.php:1184
as
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
MWMemcached\enable_compress
enable_compress( $enable)
Enable / Disable compression.
Definition: MemcachedClient.php:374
MWMemcached\set_timeout
set_timeout( $seconds, $microseconds)
Sets the timeout for new connections.
Definition: MemcachedClient.php:681
$keys
$keys
Definition: testCompression.php:63
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:1684
MWMemcached\$stats
array $stats
Command statistics.
Definition: MemcachedClient.php:107
MWMemcached\run_command
run_command( $sock, $cmd)
Passes through $cmd to the memcache server connected by $sock; returns output as an array (null array...
Definition: MemcachedClient.php:561
MWMemcached\add
add( $key, $val, $exp=0)
Adds a key/value to the memcache server if one isn't already set with that key.
Definition: MemcachedClient.php:269
$res
$res
Definition: database.txt:21
MWMemcached\sock_to_host
sock_to_host( $host)
Returns the socket for the host.
Definition: MemcachedClient.php:1061
MWMemcached\lock
lock( $key, $timeout=0)
Definition: MemcachedClient.php:338
MWMemcached\cas
cas( $casToken, $key, $value, $exp=0)
Sets a key to a given value in the memcache if the current value still corresponds to a known,...
Definition: MemcachedClient.php:623
MWMemcached\_debugprint
_debugprint( $text)
Definition: MemcachedClient.php:1090
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632