== PHP client for memcached ==
-As of this writing, MediaWiki includes version 1.0.8 of the PHP
+As of this writing, MediaWiki includes version 1.0.10 of the PHP
memcached client by Ryan Gilfether <hotrodder@rocketmail.com>.
You'll find some documentation for it in the 'php-memcached'
subdirectory under the present one.
== Keys used ==
User:
- key: $wgDBname:user:user_id:$sId
- ex: wikidb:user:user_id:51
+ key: $wgDBname:user:id:$sId
+ ex: wikidb:user:id:51
stores: instance of class User
set in: User::loadFromSession()
- cleared by: User::saveSettings()
+ cleared by: User::saveSettings(), UserTalkUpdate::doUpdate()
+
+Newtalk:
+ key: $wgDBname:newtalk:ip:$ip
+ ex: wikidb:newtalk:ip:123.45.67.89
+ stores: integer, 0 or 1
+ set in: User::loadFromDatabase()
+ cleared by: User::saveSettings() # ?
+ expiry set to 30 minutes
LinkCache:
- key: $wgDBname:linkcache:title:$title
- ex: wikidb:linkcache:title:Wikipedia:Welcome,_Newcomers!
+ key: $wgDBname:lc:title:$title
+ ex: wikidb:lc:title:Wikipedia:Welcome,_Newcomers!
stores: cur_id of page, or 0 if page does not exist
set in: LinkCache::addLink()
cleared by: LinkCache::clearBadLink()
/**
* version string
*/
-define("MC_VERSION", "1.0.9");
+define("MC_VERSION", "1.0.10");
/**
* int, buffer size used for sending and receiving
* data from sockets
* @author Ryan Gilfether <ryan@gilfether.com>
* @package MemCachedClient
* @access public
- * @version 1.0.7
+ * @version 1.0.10
*/
class MemCachedClient
{
* @var string
*/
var $errstr;
+ /**
+ * size of val to force compression; 0 turns off; defaults 1
+ * @ var int
+ */
+ var $compress = 1;
+ /**
+ * temp flag to turn compression on/off; defaults on
+ * @ var int
+ */
+ var $comp_active = 1;
+
+ /**
+ * array that contains parsed out buckets
+ * @ var array
+ */
+ var $bucket;
/**
{
$this->set_servers($options["servers"]);
$this->debug = $options["debug"];
+ $this->compress = $options["compress"];
$this->cache_sock = array();
}
}
+ /**
+ * temporarily sets compression on or off
+ * turning it off, and then back on will result in the compression threshold going
+ * back to the original setting from $options
+ * @param int $setting setting of compression (0=off|1=on)
+ */
+
+ function set_compression($setting=1) {
+ if ($setting != 0) {
+ $this->comp_active = 1;
+ } else {
+ $this->comp_active = 0;
+ }
+ }
+
+
+
/*
* PRIVATE FUNCTIONS
*/
*/
function get_sock($key)
{
- $buckets = 0;
-
if(!$this->active)
{
$this->errno = MC_ERR_NOT_ACTIVE;
$hv = is_array($key) ? intval($key[0]) : $this->_hashfunc($key);
- if(!$buckets)
+ if(!$this->buckets)
{
- $bu = $buckets = array();
+ $bu = $this->buckets = array();
foreach($this->servers as $v)
{
$bu[] = $v;
}
- $buckets = $bu;
+ $this->buckets = $bu;
}
$real_key = is_array($key) ? $key[1] : $key;
$tries = 0;
while($tries < 20)
{
- $host = @$buckets[$hv % count($buckets)];
+ $host = @$this->buckets[$hv % count($this->buckets)];
$sock = $this->sock_to_host($host);
if(is_resource($sock))
return trim($retval);
}
-
/**
* sends the command to the server
* Possible errors set are:
$flags |= 1;
}
+ if (($this->compress_active) && ($this->compress > 0) && (strlen($val) > $this->compress)) {
+ $this->_debug("_set(): compressing data. size in:".strlen($val));
+ $cval=gzcompress($val);
+ $this->_debug("_set(): done compressing data. size out:".strlen($cval));
+ if ((strlen($cval) < strlen($val)) && (strlen($val) - strlen($cval) > 2048)){
+ $flags |= 2;
+ $val=$cval;
+ }
+ unset($cval);
+ }
+
$len = strlen($val);
if (!is_int($exptime))
$exptime = 0;
if(strlen($val[$sk]) != $len_array[$sk])
continue;
+ if(@$flags_array[$sk] & 2)
+ $val[$sk] = gzuncompress($val[$sk]);
if(@$flags_array[$sk] & 1)
$val[$sk] = unserialize($val[$sk]);
*/
function _hashfunc($num)
{
- $hash = 0;
-
- foreach(preg_split('//', $num, -1, PREG_SPLIT_NO_EMPTY) as $v)
- {
- $hash = $hash * 33 + ord($v);
- }
+ $hash = sprintf("%u",crc32($num));
return $hash;
}