<?php
/**
+ * Memcached client for PHP.
+ *
* +---------------------------------------------------------------------------+
* | memcached client, PHP |
* +---------------------------------------------------------------------------+
$this->_debugprint( sprintf( "MemCache: delete %s (%s)\n", $key, $res ) );
}
- if ( $res == "DELETED" ) {
+ if ( $res == "DELETED" || $res == "NOT_FOUND" ) {
return true;
}
+
return false;
}
+ /**
+ * @param $key
+ * @param $timeout int
+ * @return bool
+ */
+ public function lock( $key, $timeout = 0 ) {
+ /* stub */
+ return true;
+ }
+
+ /**
+ * @param $key
+ * @return bool
+ */
+ public function unlock( $key ) {
+ /* stub */
+ return true;
+ }
+
// }}}
// {{{ disconnect_all()
/**
* Retrieves the value associated with the key from the memcache server
*
- * @param $key Mixed: key to retrieve
+ * @param $key array|string key to retrieve
*
* @return Mixed
*/
return false;
}
+ $key = is_array( $key ) ? $key[1] : $key;
if ( isset( $this->stats['get'] ) ) {
$this->stats['get']++;
} else {
$this->stats['get_multi'] = 1;
}
$sock_keys = array();
-
+ $socks = array();
foreach ( $keys as $key ) {
$sock = $this->get_sock( $key );
if ( !is_resource( $sock ) ) {
$sock_keys[$sock][] = $key;
}
+ $gather = array();
// Send out the requests
foreach ( $socks as $sock ) {
$cmd = 'get';
return array();
}
+ $ret = array();
while ( true ) {
$res = fgets( $sock );
$ret[] = $res;
$this->_dead_host( $host );
}
+ /**
+ * @param $host
+ */
function _dead_host( $host ) {
$parts = explode( ':', $host );
$ip = $parts[0];
}
$hv = is_array( $key ) ? intval( $key[0] ) : $this->_hashfunc( $key );
-
if ( $this->_buckets === null ) {
+ $bu = array();
foreach ( $this->_servers as $v ) {
if ( is_array( $v ) ) {
for( $i = 0; $i < $v[1]; $i++ ) {
* @access private
*/
function _hashfunc( $key ) {
- # Hash function must on [0,0x7ffffff]
+ # Hash function must be in [0,0x7ffffff]
# We take the first 31 bits of the MD5 hash, which unlike the hash
# function used in a previous version of this client, works
return hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
/**
* Perform increment/decriment on $key
*
- * @param $cmd String: command to perform
- * @param $key String: key to perform it on
- * @param $amt Integer: amount to adjust
+ * @param $cmd String command to perform
+ * @param $key String|array key to perform it on
+ * @param $amt Integer amount to adjust
*
* @return Integer: new value of $key
* @access private
$this->stats[$cmd] = 1;
}
if ( !$this->_safe_fwrite( $sock, "$cmd $key $amt\r\n" ) ) {
- return $this->_dead_sock( $sock );
+ $this->_dead_sock( $sock );
+ return null;
}
$line = fgets( $sock );
* @param $sock Resource: socket to read from
* @param $ret Array: returned values
*
+ * @return bool|int
* @access private
*/
function _load_items( $sock, &$ret ) {
} else {
$this->stats[$cmd] = 1;
}
-
- // Memcached doesn't seem to handle very high TTL values very well,
- // so clamp them at 30 days
- if ( $exp > 2592000 ) {
- $exp = 2592000;
- }
$flags = 0;
}
}
if ( !$this->_safe_fwrite( $sock, "$cmd $key $flags $exp $len\r\n$val\r\n" ) ) {
- return $this->_dead_sock( $sock );
+ $this->_dead_sock( $sock );
+ return false;
}
$line = trim( fgets( $sock ) );
}
if ( !$this->_connect_sock( $sock, $host ) ) {
- return $this->_dead_host( $host );
+ $this->_dead_host( $host );
+ return null;
}
// Do not buffer writes
return $this->_cache_sock[$host];
}
+ /**
+ * @param $str string
+ */
function _debugprint( $str ) {
print( $str );
}
/**
* Original behaviour
+ * @param $f
+ * @param $buf
+ * @param $len bool
+ * @return int
*/
function _safe_fwrite( $f, $buf, $len = false ) {
if ( $len === false ) {
/**
* Flush the read buffer of a stream
+ * @param $f Resource
*/
function _flush_read_buffer( $f ) {
if ( !is_resource( $f ) ) {
// }}}
class MemCachedClientforWiki extends MWMemcached {
+
function _debugprint( $text ) {
- wfDebug( "memcached: $text" );
+ global $wgDebugLogGroups;
+ if( !isset( $wgDebugLogGroups['memcached'] ) ) {
+ # Prefix message since it will end up in main debug log file
+ $text = "memcached: $text";
+ }
+ wfDebugLog( 'memcached', $text );
}
}