MediaWiki REL1_31
MemcachedClient.php
Go to the documentation of this file.
1<?php
2// phpcs:ignoreFile -- It's an external lib and it isn't. Let's not bother.
69use Psr\Log\LoggerInterface;
70use Psr\Log\NullLogger;
71
72// {{{ class MemcachedClient
80 // {{{ properties
81 // {{{ public
82
83 // {{{ constants
84 // {{{ flags
85
89 const SERIALIZED = 1;
90
94 const COMPRESSED = 2;
95
99 const INTVAL = 4;
100
101 // }}}
102
107
108 // }}}
109
116 public $stats;
117
118 // }}}
119 // {{{ private
120
128
135 public $_debug;
136
144
152
160
168
176
184
191 public $_servers;
192
199 public $_buckets;
200
208
215 public $_active;
216
224
232
237
242
246 private $_logger;
247
248 // }}}
249 // }}}
250 // {{{ methods
251 // {{{ public functions
252 // {{{ memcached()
253
261 public function __construct( $args ) {
262 $this->set_servers( isset( $args['servers'] ) ? $args['servers'] : array() );
263 $this->_debug = isset( $args['debug'] ) ? $args['debug'] : false;
264 $this->stats = array();
265 $this->_compress_threshold = isset( $args['compress_threshold'] ) ? $args['compress_threshold'] : 0;
266 $this->_persistent = isset( $args['persistent'] ) ? $args['persistent'] : false;
267 $this->_compress_enable = true;
268 $this->_have_zlib = function_exists( 'gzcompress' );
269
270 $this->_cache_sock = array();
271 $this->_host_dead = array();
272
273 $this->_timeout_seconds = 0;
274 $this->_timeout_microseconds = isset( $args['timeout'] ) ? $args['timeout'] : 500000;
275
276 $this->_connect_timeout = isset( $args['connect_timeout'] ) ? $args['connect_timeout'] : 0.1;
277 $this->_connect_attempts = 2;
278
279 $this->_logger = isset( $args['logger'] ) ? $args['logger'] : new NullLogger();
280 }
281
282 // }}}
283 // {{{ add()
284
299 public function add( $key, $val, $exp = 0 ) {
300 return $this->_set( 'add', $key, $val, $exp );
301 }
302
303 // }}}
304 // {{{ decr()
305
314 public function decr( $key, $amt = 1 ) {
315 return $this->_incrdecr( 'decr', $key, $amt );
316 }
317
318 // }}}
319 // {{{ delete()
320
329 public function delete( $key, $time = 0 ) {
330 if ( !$this->_active ) {
331 return false;
332 }
333
334 $sock = $this->get_sock( $key );
335 if ( !is_resource( $sock ) ) {
336 return false;
337 }
338
339 $key = is_array( $key ) ? $key[1] : $key;
340
341 if ( isset( $this->stats['delete'] ) ) {
342 $this->stats['delete']++;
343 } else {
344 $this->stats['delete'] = 1;
345 }
346 $cmd = "delete $key $time\r\n";
347 if ( !$this->_fwrite( $sock, $cmd ) ) {
348 return false;
349 }
350 $res = $this->_fgets( $sock );
351
352 if ( $this->_debug ) {
353 $this->_debugprint( sprintf( "MemCache: delete %s (%s)", $key, $res ) );
354 }
355
356 if ( $res == "DELETED" || $res == "NOT_FOUND" ) {
357 return true;
358 }
359
360 return false;
361 }
362
371 public function touch( $key, $time = 0 ) {
372 if ( !$this->_active ) {
373 return false;
374 }
375
376 $sock = $this->get_sock( $key );
377 if ( !is_resource( $sock ) ) {
378 return false;
379 }
380
381 $key = is_array( $key ) ? $key[1] : $key;
382
383 if ( isset( $this->stats['touch'] ) ) {
384 $this->stats['touch']++;
385 } else {
386 $this->stats['touch'] = 1;
387 }
388 $cmd = "touch $key $time\r\n";
389 if ( !$this->_fwrite( $sock, $cmd ) ) {
390 return false;
391 }
392 $res = $this->_fgets( $sock );
393
394 if ( $this->_debug ) {
395 $this->_debugprint( sprintf( "MemCache: touch %s (%s)", $key, $res ) );
396 }
397
398 if ( $res == "TOUCHED" ) {
399 return true;
400 }
401
402 return false;
403 }
404
410 public function lock( $key, $timeout = 0 ) {
411 /* stub */
412 return true;
413 }
414
419 public function unlock( $key ) {
420 /* stub */
421 return true;
422 }
423
424 // }}}
425 // {{{ disconnect_all()
426
430 public function disconnect_all() {
431 foreach ( $this->_cache_sock as $sock ) {
432 fclose( $sock );
433 }
434
435 $this->_cache_sock = array();
436 }
437
438 // }}}
439 // {{{ enable_compress()
440
446 public function enable_compress( $enable ) {
447 $this->_compress_enable = $enable;
448 }
449
450 // }}}
451 // {{{ forget_dead_hosts()
452
456 public function forget_dead_hosts() {
457 $this->_host_dead = array();
458 }
459
460 // }}}
461 // {{{ get()
462
471 public function get( $key, &$casToken = null ) {
472 if ( $this->_debug ) {
473 $this->_debugprint( "get($key)" );
474 }
475
476 if ( !is_array( $key ) && strval( $key ) === '' ) {
477 $this->_debugprint( "Skipping key which equals to an empty string" );
478 return false;
479 }
480
481 if ( !$this->_active ) {
482 return false;
483 }
484
485 $sock = $this->get_sock( $key );
486
487 if ( !is_resource( $sock ) ) {
488 return false;
489 }
490
491 $key = is_array( $key ) ? $key[1] : $key;
492 if ( isset( $this->stats['get'] ) ) {
493 $this->stats['get']++;
494 } else {
495 $this->stats['get'] = 1;
496 }
497
498 $cmd = "gets $key\r\n";
499 if ( !$this->_fwrite( $sock, $cmd ) ) {
500 return false;
501 }
502
503 $val = array();
504 $this->_load_items( $sock, $val, $casToken );
505
506 if ( $this->_debug ) {
507 foreach ( $val as $k => $v ) {
508 $this->_debugprint( sprintf( "MemCache: sock %s got %s", serialize( $sock ), $k ) );
509 }
510 }
511
512 $value = false;
513 if ( isset( $val[$key] ) ) {
514 $value = $val[$key];
515 }
516 return $value;
517 }
518
519 // }}}
520 // {{{ get_multi()
521
529 public function get_multi( $keys ) {
530 if ( !$this->_active ) {
531 return array();
532 }
533
534 if ( isset( $this->stats['get_multi'] ) ) {
535 $this->stats['get_multi']++;
536 } else {
537 $this->stats['get_multi'] = 1;
538 }
539 $sock_keys = array();
540 $socks = array();
541 foreach ( $keys as $key ) {
542 $sock = $this->get_sock( $key );
543 if ( !is_resource( $sock ) ) {
544 continue;
545 }
546 $key = is_array( $key ) ? $key[1] : $key;
547 $sockValue = intval( $sock );
548 if ( !isset( $sock_keys[$sockValue] ) ) {
549 $sock_keys[$sockValue] = array();
550 $socks[] = $sock;
551 }
552 $sock_keys[$sockValue][] = $key;
553 }
554
555 $gather = array();
556 // Send out the requests
557 foreach ( $socks as $sock ) {
558 $cmd = 'gets';
559 foreach ( $sock_keys[intval( $sock )] as $key ) {
560 $cmd .= ' ' . $key;
561 }
562 $cmd .= "\r\n";
563
564 if ( $this->_fwrite( $sock, $cmd ) ) {
565 $gather[] = $sock;
566 }
567 }
568
569 // Parse responses
570 $val = array();
571 foreach ( $gather as $sock ) {
572 $this->_load_items( $sock, $val, $casToken );
573 }
574
575 if ( $this->_debug ) {
576 foreach ( $val as $k => $v ) {
577 $this->_debugprint( sprintf( "MemCache: got %s", $k ) );
578 }
579 }
580
581 return $val;
582 }
583
584 // }}}
585 // {{{ incr()
586
597 public function incr( $key, $amt = 1 ) {
598 return $this->_incrdecr( 'incr', $key, $amt );
599 }
600
601 // }}}
602 // {{{ replace()
603
617 public function replace( $key, $value, $exp = 0 ) {
618 return $this->_set( 'replace', $key, $value, $exp );
619 }
620
621 // }}}
622 // {{{ run_command()
623
633 public function run_command( $sock, $cmd ) {
634 if ( !is_resource( $sock ) ) {
635 return array();
636 }
637
638 if ( !$this->_fwrite( $sock, $cmd ) ) {
639 return array();
640 }
641
642 $ret = array();
643 while ( true ) {
644 $res = $this->_fgets( $sock );
645 $ret[] = $res;
646 if ( preg_match( '/^END/', $res ) ) {
647 break;
648 }
649 if ( strlen( $res ) == 0 ) {
650 break;
651 }
652 }
653 return $ret;
654 }
655
656 // }}}
657 // {{{ set()
658
673 public function set( $key, $value, $exp = 0 ) {
674 return $this->_set( 'set', $key, $value, $exp );
675 }
676
677 // }}}
678 // {{{ cas()
679
695 public function cas( $casToken, $key, $value, $exp = 0 ) {
696 return $this->_set( 'cas', $key, $value, $exp, $casToken );
697 }
698
699 // }}}
700 // {{{ set_compress_threshold()
701
707 public function set_compress_threshold( $thresh ) {
708 $this->_compress_threshold = $thresh;
709 }
710
711 // }}}
712 // {{{ set_debug()
713
720 public function set_debug( $dbg ) {
721 $this->_debug = $dbg;
722 }
723
724 // }}}
725 // {{{ set_servers()
726
733 public function set_servers( $list ) {
734 $this->_servers = $list;
735 $this->_active = count( $list );
736 $this->_buckets = null;
737 $this->_bucketcount = 0;
738
739 $this->_single_sock = null;
740 if ( $this->_active == 1 ) {
741 $this->_single_sock = $this->_servers[0];
742 }
743 }
744
751 public function set_timeout( $seconds, $microseconds ) {
752 $this->_timeout_seconds = $seconds;
753 $this->_timeout_microseconds = $microseconds;
754 }
755
756 // }}}
757 // }}}
758 // {{{ private methods
759 // {{{ _close_sock()
760
768 function _close_sock( $sock ) {
769 $host = array_search( $sock, $this->_cache_sock );
770 fclose( $this->_cache_sock[$host] );
771 unset( $this->_cache_sock[$host] );
772 }
773
774 // }}}
775 // {{{ _connect_sock()
776
786 function _connect_sock( &$sock, $host ) {
787 list( $ip, $port ) = preg_split( '/:(?=\d)/', $host );
788 $sock = false;
789 $timeout = $this->_connect_timeout;
790 $errno = $errstr = null;
791 for ( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) {
792 Wikimedia\suppressWarnings();
793 if ( $this->_persistent == 1 ) {
794 $sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout );
795 } else {
796 $sock = fsockopen( $ip, $port, $errno, $errstr, $timeout );
797 }
798 Wikimedia\restoreWarnings();
799 }
800 if ( !$sock ) {
801 $this->_error_log( "Error connecting to $host: $errstr" );
802 $this->_dead_host( $host );
803 return false;
804 }
805
806 // Initialise timeout
807 stream_set_timeout( $sock, $this->_timeout_seconds, $this->_timeout_microseconds );
808
809 // If the connection was persistent, flush the read buffer in case there
810 // was a previous incomplete request on this connection
811 if ( $this->_persistent ) {
812 $this->_flush_read_buffer( $sock );
813 }
814 return true;
815 }
816
817 // }}}
818 // {{{ _dead_sock()
819
827 function _dead_sock( $sock ) {
828 $host = array_search( $sock, $this->_cache_sock );
829 $this->_dead_host( $host );
830 }
831
835 function _dead_host( $host ) {
836 $ip = explode( ':', $host )[0];
837 $this->_host_dead[$ip] = time() + 30 + intval( rand( 0, 10 ) );
838 $this->_host_dead[$host] = $this->_host_dead[$ip];
839 unset( $this->_cache_sock[$host] );
840 }
841
842 // }}}
843 // {{{ get_sock()
844
853 function get_sock( $key ) {
854 if ( !$this->_active ) {
855 return false;
856 }
857
858 if ( $this->_single_sock !== null ) {
859 return $this->sock_to_host( $this->_single_sock );
860 }
861
862 $hv = is_array( $key ) ? intval( $key[0] ) : $this->_hashfunc( $key );
863 if ( $this->_buckets === null ) {
864 $bu = array();
865 foreach ( $this->_servers as $v ) {
866 if ( is_array( $v ) ) {
867 for ( $i = 0; $i < $v[1]; $i++ ) {
868 $bu[] = $v[0];
869 }
870 } else {
871 $bu[] = $v;
872 }
873 }
874 $this->_buckets = $bu;
875 $this->_bucketcount = count( $bu );
876 }
877
878 $realkey = is_array( $key ) ? $key[1] : $key;
879 for ( $tries = 0; $tries < 20; $tries++ ) {
880 $host = $this->_buckets[$hv % $this->_bucketcount];
881 $sock = $this->sock_to_host( $host );
882 if ( is_resource( $sock ) ) {
883 return $sock;
884 }
885 $hv = $this->_hashfunc( $hv . $realkey );
886 }
887
888 return false;
889 }
890
891 // }}}
892 // {{{ _hashfunc()
893
902 function _hashfunc( $key ) {
903 # Hash function must be in [0,0x7ffffff]
904 # We take the first 31 bits of the MD5 hash, which unlike the hash
905 # function used in a previous version of this client, works
906 return hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
907 }
908
909 // }}}
910 // {{{ _incrdecr()
911
922 function _incrdecr( $cmd, $key, $amt = 1 ) {
923 if ( !$this->_active ) {
924 return null;
925 }
926
927 $sock = $this->get_sock( $key );
928 if ( !is_resource( $sock ) ) {
929 return null;
930 }
931
932 $key = is_array( $key ) ? $key[1] : $key;
933 if ( isset( $this->stats[$cmd] ) ) {
934 $this->stats[$cmd]++;
935 } else {
936 $this->stats[$cmd] = 1;
937 }
938 if ( !$this->_fwrite( $sock, "$cmd $key $amt\r\n" ) ) {
939 return null;
940 }
941
942 $line = $this->_fgets( $sock );
943 $match = array();
944 if ( !preg_match( '/^(\d+)/', $line, $match ) ) {
945 return null;
946 }
947 return $match[1];
948 }
949
950 // }}}
951 // {{{ _load_items()
952
963 function _load_items( $sock, &$ret, &$casToken = null ) {
964 $results = array();
965
966 while ( 1 ) {
967 $decl = $this->_fgets( $sock );
968
969 if ( $decl === false ) {
970 /*
971 * If nothing can be read, something is wrong because we know exactly when
972 * to stop reading (right after "END") and we return right after that.
973 */
974 return false;
975 } elseif ( preg_match( '/^VALUE (\S+) (\d+) (\d+) (\d+)$/', $decl, $match ) ) {
976 /*
977 * Read all data returned. This can be either one or multiple values.
978 * Save all that data (in an array) to be processed later: we'll first
979 * want to continue reading until "END" before doing anything else,
980 * to make sure that we don't leave our client in a state where it's
981 * output is not yet fully read.
982 */
983 $results[] = array(
984 $match[1], // rkey
985 $match[2], // flags
986 $match[3], // len
987 $match[4], // casToken
988 $this->_fread( $sock, $match[3] + 2 ), // data
989 );
990 } elseif ( $decl == "END" ) {
991 if ( count( $results ) == 0 ) {
992 return false;
993 }
994
999 foreach ( $results as $vars ) {
1000 list( $rkey, $flags, $len, $casToken, $data ) = $vars;
1001
1002 if ( $data === false || substr( $data, -2 ) !== "\r\n" ) {
1003 $this->_handle_error( $sock,
1004 'line ending missing from data block from $1' );
1005 return false;
1006 }
1007 $data = substr( $data, 0, -2 );
1008 $ret[$rkey] = $data;
1009
1010 if ( $this->_have_zlib && $flags & self::COMPRESSED ) {
1011 $ret[$rkey] = gzuncompress( $ret[$rkey] );
1012 }
1013
1014 /*
1015 * This unserialize is the exact reason that we only want to
1016 * process data after having read until "END" (instead of doing
1017 * this right away): "unserialize" can trigger outside code:
1018 * in the event that $ret[$rkey] is a serialized object,
1019 * unserializing it will trigger __wakeup() if present. If that
1020 * function attempted to read from memcached (while we did not
1021 * yet read "END"), these 2 calls would collide.
1022 */
1023 if ( $flags & self::SERIALIZED ) {
1024 $ret[$rkey] = unserialize( $ret[$rkey] );
1025 } elseif ( $flags & self::INTVAL ) {
1026 $ret[$rkey] = intval( $ret[$rkey] );
1027 }
1028 }
1029
1030 return true;
1031 } else {
1032 $this->_handle_error( $sock, 'Error parsing response from $1' );
1033 return false;
1034 }
1035 }
1036 }
1037
1038 // }}}
1039 // {{{ _set()
1040
1057 function _set( $cmd, $key, $val, $exp, $casToken = null ) {
1058 if ( !$this->_active ) {
1059 return false;
1060 }
1061
1062 $sock = $this->get_sock( $key );
1063 if ( !is_resource( $sock ) ) {
1064 return false;
1065 }
1066
1067 if ( isset( $this->stats[$cmd] ) ) {
1068 $this->stats[$cmd]++;
1069 } else {
1070 $this->stats[$cmd] = 1;
1071 }
1072
1073 $flags = 0;
1074
1075 if ( is_int( $val ) ) {
1076 $flags |= self::INTVAL;
1077 } elseif ( !is_scalar( $val ) ) {
1078 $val = serialize( $val );
1079 $flags |= self::SERIALIZED;
1080 if ( $this->_debug ) {
1081 $this->_debugprint( sprintf( "client: serializing data as it is not scalar" ) );
1082 }
1083 }
1084
1085 $len = strlen( $val );
1086
1087 if ( $this->_have_zlib && $this->_compress_enable
1088 && $this->_compress_threshold && $len >= $this->_compress_threshold
1089 ) {
1090 $c_val = gzcompress( $val, 9 );
1091 $c_len = strlen( $c_val );
1092
1093 if ( $c_len < $len * ( 1 - self::COMPRESSION_SAVINGS ) ) {
1094 if ( $this->_debug ) {
1095 $this->_debugprint( sprintf( "client: compressing data; was %d bytes is now %d bytes", $len, $c_len ) );
1096 }
1097 $val = $c_val;
1098 $len = $c_len;
1099 $flags |= self::COMPRESSED;
1100 }
1101 }
1102
1103 $command = "$cmd $key $flags $exp $len";
1104 if ( $casToken ) {
1105 $command .= " $casToken";
1106 }
1107
1108 if ( !$this->_fwrite( $sock, "$command\r\n$val\r\n" ) ) {
1109 return false;
1110 }
1111
1112 $line = $this->_fgets( $sock );
1113
1114 if ( $this->_debug ) {
1115 $this->_debugprint( sprintf( "%s %s (%s)", $cmd, $key, $line ) );
1116 }
1117 if ( $line === "STORED" ) {
1118 return true;
1119 } elseif ( $line === "NOT_STORED" && $cmd === "set" ) {
1120 // "Not stored" is always used as the mcrouter response with AllAsyncRoute
1121 return true;
1122 }
1123
1124 return false;
1125 }
1126
1127 // }}}
1128 // {{{ sock_to_host()
1129
1138 function sock_to_host( $host ) {
1139 if ( isset( $this->_cache_sock[$host] ) ) {
1140 return $this->_cache_sock[$host];
1141 }
1142
1143 $sock = null;
1144 $now = time();
1145 list( $ip, /* $port */) = explode( ':', $host );
1146 if ( isset( $this->_host_dead[$host] ) && $this->_host_dead[$host] > $now ||
1147 isset( $this->_host_dead[$ip] ) && $this->_host_dead[$ip] > $now
1148 ) {
1149 return null;
1150 }
1151
1152 if ( !$this->_connect_sock( $sock, $host ) ) {
1153 return null;
1154 }
1155
1156 // Do not buffer writes
1157 stream_set_write_buffer( $sock, 0 );
1158
1159 $this->_cache_sock[$host] = $sock;
1160
1161 return $this->_cache_sock[$host];
1162 }
1163
1167 function _debugprint( $text ) {
1168 $this->_logger->debug( $text );
1169 }
1170
1174 function _error_log( $text ) {
1175 $this->_logger->error( "Memcached error: $text" );
1176 }
1177
1185 function _fwrite( $sock, $buf ) {
1186 $bytesWritten = 0;
1187 $bufSize = strlen( $buf );
1188 while ( $bytesWritten < $bufSize ) {
1189 $result = fwrite( $sock, $buf );
1190 $data = stream_get_meta_data( $sock );
1191 if ( $data['timed_out'] ) {
1192 $this->_handle_error( $sock, 'timeout writing to $1' );
1193 return false;
1194 }
1195 // Contrary to the documentation, fwrite() returns zero on error in PHP 5.3.
1196 if ( $result === false || $result === 0 ) {
1197 $this->_handle_error( $sock, 'error writing to $1' );
1198 return false;
1199 }
1200 $bytesWritten += $result;
1201 }
1202
1203 return true;
1204 }
1205
1212 function _handle_error( $sock, $msg ) {
1213 $peer = stream_socket_get_name( $sock, true );
1214 if ( strval( $peer ) === '' ) {
1215 $peer = array_search( $sock, $this->_cache_sock );
1216 if ( $peer === false ) {
1217 $peer = '[unknown host]';
1218 }
1219 }
1220 $msg = str_replace( '$1', $peer, $msg );
1221 $this->_error_log( "$msg" );
1222 $this->_dead_sock( $sock );
1223 }
1224
1233 function _fread( $sock, $len ) {
1234 $buf = '';
1235 while ( $len > 0 ) {
1236 $result = fread( $sock, $len );
1237 $data = stream_get_meta_data( $sock );
1238 if ( $data['timed_out'] ) {
1239 $this->_handle_error( $sock, 'timeout reading from $1' );
1240 return false;
1241 }
1242 if ( $result === false ) {
1243 $this->_handle_error( $sock, 'error reading buffer from $1' );
1244 return false;
1245 }
1246 if ( $result === '' ) {
1247 // This will happen if the remote end of the socket is shut down
1248 $this->_handle_error( $sock, 'unexpected end of file reading from $1' );
1249 return false;
1250 }
1251 $len -= strlen( $result );
1252 $buf .= $result;
1253 }
1254 return $buf;
1255 }
1256
1264 function _fgets( $sock ) {
1265 $result = fgets( $sock );
1266 // fgets() may return a partial line if there is a select timeout after
1267 // a successful recv(), so we have to check for a timeout even if we
1268 // got a string response.
1269 $data = stream_get_meta_data( $sock );
1270 if ( $data['timed_out'] ) {
1271 $this->_handle_error( $sock, 'timeout reading line from $1' );
1272 return false;
1273 }
1274 if ( $result === false ) {
1275 $this->_handle_error( $sock, 'error reading line from $1' );
1276 return false;
1277 }
1278 if ( substr( $result, -2 ) === "\r\n" ) {
1279 $result = substr( $result, 0, -2 );
1280 } elseif ( substr( $result, -1 ) === "\n" ) {
1281 $result = substr( $result, 0, -1 );
1282 } else {
1283 $this->_handle_error( $sock, 'line ending missing in response from $1' );
1284 return false;
1285 }
1286 return $result;
1287 }
1288
1293 function _flush_read_buffer( $f ) {
1294 if ( !is_resource( $f ) ) {
1295 return;
1296 }
1297 $r = array( $f );
1298 $w = null;
1299 $e = null;
1300 $n = stream_select( $r, $w, $e, 0, 0 );
1301 while ( $n == 1 && !feof( $f ) ) {
1302 fread( $f, 1024 );
1303 $r = array( $f );
1304 $w = null;
1305 $e = null;
1306 $n = stream_select( $r, $w, $e, 0, 0 );
1307 }
1308 }
1309
1310 // }}}
1311 // }}}
1312 // }}}
1313}
1314
1315// }}}
serialize()
unserialize( $serialized)
$line
Definition cdb.php:59
$command
Definition cdb.php:65
if( $line===false) $args
Definition cdb.php:64
memcached client class implemented using (p)fsockopen()
set_debug( $dbg)
Set the debug flag.
array $_cache_sock
Cached Sockets that are connected.
const SERIALIZED
Flag: indicates data is serialized.
const COMPRESSION_SAVINGS
Minimum savings to store data compressed.
_hashfunc( $key)
Creates a hash integer based on the $key.
set_compress_threshold( $thresh)
Set the compression threshold.
_fread( $sock, $len)
Read the specified number of bytes from a stream.
array $_servers
Array containing ip:port or array(ip:port, weight)
bool $_compress_enable
Do we want to use compression?
decr( $key, $amt=1)
Decrease a value stored on the memcache server.
const INTVAL
Flag: indicates data is an integer.
int $_compress_threshold
At how many bytes should we compress?
int $_timeout_seconds
Stream timeout in seconds.
disconnect_all()
Disconnects all connected sockets.
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,...
array $_buckets
Our bit buckets.
set_timeout( $seconds, $microseconds)
Sets the timeout for new connections.
_fgets( $sock)
Read a line from a stream.
incr( $key, $amt=1)
Increments $key (optionally) by $amt.
forget_dead_hosts()
Forget about all of the dead hosts.
_incrdecr( $cmd, $key, $amt=1)
Perform increment/decriment on $key.
$_connect_attempts
Number of connection attempts for each server.
add( $key, $val, $exp=0)
Adds a key/value to the memcache server if one isn't already set with that key.
_handle_error( $sock, $msg)
Handle an I/O error.
sock_to_host( $host)
Returns the socket for the host.
$_connect_timeout
Connect timeout in seconds.
touch( $key, $time=0)
Changes the TTL on a key from the server to $time.
bool $_have_zlib
Is compression available?
int $_bucketcount
Total # of bit buckets we have.
_fwrite( $sock, $buf)
Write to a stream.
bool $_debug
Current debug status; 0 - none to 9 - profiling.
replace( $key, $value, $exp=0)
Overwrites an existing value for key; only works if key is already set.
set_servers( $list)
Set the server list to distribute key gets and puts between.
_load_items( $sock, &$ret, &$casToken=null)
Load items into $ret from $sock.
string $_single_sock
If only using one server; contains ip:port to connect to.
get_multi( $keys)
Get multiple keys from the server(s)
_close_sock( $sock)
Close the specified socket.
run_command( $sock, $cmd)
Passes through $cmd to the memcache server connected by $sock; returns output as an array (null array...
_set( $cmd, $key, $val, $exp, $casToken=null)
Performs the requested storage operation to the memcache server.
LoggerInterface $_logger
int $_timeout_microseconds
Stream timeout in microseconds.
__construct( $args)
Memcache initializer.
_flush_read_buffer( $f)
Flush the read buffer of a stream.
enable_compress( $enable)
Enable / Disable compression.
array $_host_dead
Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'.
const COMPRESSED
Flag: indicates data is compressed.
get_sock( $key)
get_sock
_dead_sock( $sock)
Marks a host as dead until 30-40 seconds in the future.
_connect_sock(&$sock, $host)
Connects $sock to $host, timing out after $timeout.
array $stats
Command statistics.
lock( $key, $timeout=0)
bool $_persistent
Are we using persistent links?
$res
Definition database.txt:21
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
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2228
namespace being checked & $result
Definition hooks.txt:2323
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1795
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:2005
returning false will NOT prevent logging $e
Definition hooks.txt:2176