r1587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1586‎ | r1587 | r1588 >
Date:07:03, 21 August 2003
Author:vibber
Status:old
Tags:
Comment:
Update memcached client to 1.0.10
Modified paths:
  • /trunk/phase3/docs/memcached.doc (modified) (history)
  • /trunk/phase3/docs/php-memcached/ChangeLog (modified) (history)
  • /trunk/phase3/docs/php-memcached/Documentation (modified) (history)
  • /trunk/phase3/includes/MemCachedClient.inc.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/memcached.doc
@@ -72,7 +72,7 @@
7373
7474 == PHP client for memcached ==
7575
76 -As of this writing, MediaWiki includes version 1.0.8 of the PHP
 76+As of this writing, MediaWiki includes version 1.0.10 of the PHP
7777 memcached client by Ryan Gilfether <hotrodder@rocketmail.com>.
7878 You'll find some documentation for it in the 'php-memcached'
7979 subdirectory under the present one.
@@ -88,15 +88,23 @@
8989 == Keys used ==
9090
9191 User:
92 - key: $wgDBname:user:user_id:$sId
93 - ex: wikidb:user:user_id:51
 92+ key: $wgDBname:user:id:$sId
 93+ ex: wikidb:user:id:51
9494 stores: instance of class User
9595 set in: User::loadFromSession()
96 - cleared by: User::saveSettings()
 96+ cleared by: User::saveSettings(), UserTalkUpdate::doUpdate()
 97+
 98+Newtalk:
 99+ key: $wgDBname:newtalk:ip:$ip
 100+ ex: wikidb:newtalk:ip:123.45.67.89
 101+ stores: integer, 0 or 1
 102+ set in: User::loadFromDatabase()
 103+ cleared by: User::saveSettings() # ?
 104+ expiry set to 30 minutes
97105
98106 LinkCache:
99 - key: $wgDBname:linkcache:title:$title
100 - ex: wikidb:linkcache:title:Wikipedia:Welcome,_Newcomers!
 107+ key: $wgDBname:lc:title:$title
 108+ ex: wikidb:lc:title:Wikipedia:Welcome,_Newcomers!
101109 stores: cur_id of page, or 0 if page does not exist
102110 set in: LinkCache::addLink()
103111 cleared by: LinkCache::clearBadLink()
Index: trunk/phase3/docs/php-memcached/ChangeLog
@@ -1,3 +1,12 @@
 2+Release 1.0.10
 3+--------------
 4+* bug fix: changes hashing function to crc32, sprintf %u
 5+* feature: optional compression
 6+
 7+Release 1.0.9
 8+-------------
 9+* protocol parsing bug
 10+
211 Release 1.0.8
312 -------------
413 * whitespace/punctuation/wording cleanups
Index: trunk/phase3/docs/php-memcached/Documentation
@@ -158,8 +158,9 @@
159159 MC_ERR_LOADITEM_BYTES // _load_items bytes read larger than bytes available
160160 MC_ERR_GET // failed to get value associated with key
161161
 162+// Turns compression on or off; 0=off, 1=on
 163+MemCacheClient::set_compression($setting)
162164
163 -
164165 EXAMPLE:
165166 <?php
166167 require("MemCachedClient.inc.php");
Index: trunk/phase3/includes/MemCachedClient.inc.php
@@ -19,7 +19,7 @@
2020 /**
2121 * version string
2222 */
23 -define("MC_VERSION", "1.0.9");
 23+define("MC_VERSION", "1.0.10");
2424 /**
2525 * int, buffer size used for sending and receiving
2626 * data from sockets
@@ -51,7 +51,7 @@
5252 * @author Ryan Gilfether <ryan@gilfether.com>
5353 * @package MemCachedClient
5454 * @access public
55 - * @version 1.0.7
 55+ * @version 1.0.10
5656 */
5757 class MemCachedClient
5858 {
@@ -90,8 +90,24 @@
9191 * @var string
9292 */
9393 var $errstr;
 94+ /**
 95+ * size of val to force compression; 0 turns off; defaults 1
 96+ * @ var int
 97+ */
 98+ var $compress = 1;
 99+ /**
 100+ * temp flag to turn compression on/off; defaults on
 101+ * @ var int
 102+ */
 103+ var $comp_active = 1;
94104
 105+ /**
 106+ * array that contains parsed out buckets
 107+ * @ var array
 108+ */
 109+ var $bucket;
95110
 111+
96112 /**
97113 * Constructor
98114 *
@@ -116,6 +132,7 @@
117133 {
118134 $this->set_servers($options["servers"]);
119135 $this->debug = $options["debug"];
 136+ $this->compress = $options["compress"];
120137 $this->cache_sock = array();
121138 }
122139
@@ -550,6 +567,23 @@
551568 }
552569
553570
 571+ /**
 572+ * temporarily sets compression on or off
 573+ * turning it off, and then back on will result in the compression threshold going
 574+ * back to the original setting from $options
 575+ * @param int $setting setting of compression (0=off|1=on)
 576+ */
 577+
 578+ function set_compression($setting=1) {
 579+ if ($setting != 0) {
 580+ $this->comp_active = 1;
 581+ } else {
 582+ $this->comp_active = 0;
 583+ }
 584+ }
 585+
 586+
 587+
554588 /*
555589 * PRIVATE FUNCTIONS
556590 */
@@ -637,8 +671,6 @@
638672 */
639673 function get_sock($key)
640674 {
641 - $buckets = 0;
642 -
643675 if(!$this->active)
644676 {
645677 $this->errno = MC_ERR_NOT_ACTIVE;
@@ -652,9 +684,9 @@
653685
654686 $hv = is_array($key) ? intval($key[0]) : $this->_hashfunc($key);
655687
656 - if(!$buckets)
 688+ if(!$this->buckets)
657689 {
658 - $bu = $buckets = array();
 690+ $bu = $this->buckets = array();
659691
660692 foreach($this->servers as $v)
661693 {
@@ -667,14 +699,14 @@
668700 $bu[] = $v;
669701 }
670702
671 - $buckets = $bu;
 703+ $this->buckets = $bu;
672704 }
673705
674706 $real_key = is_array($key) ? $key[1] : $key;
675707 $tries = 0;
676708 while($tries < 20)
677709 {
678 - $host = @$buckets[$hv % count($buckets)];
 710+ $host = @$this->buckets[$hv % count($this->buckets)];
679711 $sock = $this->sock_to_host($host);
680712
681713 if(is_resource($sock))
@@ -783,7 +815,6 @@
784816 return trim($retval);
785817 }
786818
787 -
788819 /**
789820 * sends the command to the server
790821 * Possible errors set are:
@@ -837,6 +868,17 @@
838869 $flags |= 1;
839870 }
840871
 872+ if (($this->compress_active) && ($this->compress > 0) && (strlen($val) > $this->compress)) {
 873+ $this->_debug("_set(): compressing data. size in:".strlen($val));
 874+ $cval=gzcompress($val);
 875+ $this->_debug("_set(): done compressing data. size out:".strlen($cval));
 876+ if ((strlen($cval) < strlen($val)) && (strlen($val) - strlen($cval) > 2048)){
 877+ $flags |= 2;
 878+ $val=$cval;
 879+ }
 880+ unset($cval);
 881+ }
 882+
841883 $len = strlen($val);
842884 if (!is_int($exptime))
843885 $exptime = 0;
@@ -1034,6 +1076,8 @@
10351077
10361078 if(strlen($val[$sk]) != $len_array[$sk])
10371079 continue;
 1080+ if(@$flags_array[$sk] & 2)
 1081+ $val[$sk] = gzuncompress($val[$sk]);
10381082
10391083 if(@$flags_array[$sk] & 1)
10401084 $val[$sk] = unserialize($val[$sk]);
@@ -1078,13 +1122,8 @@
10791123 */
10801124 function _hashfunc($num)
10811125 {
1082 - $hash = 0;
 1126+ $hash = sprintf("%u",crc32($num));
10831127
1084 - foreach(preg_split('//', $num, -1, PREG_SPLIT_NO_EMPTY) as $v)
1085 - {
1086 - $hash = $hash * 33 + ord($v);
1087 - }
1088 -
10891128 return $hash;
10901129 }
10911130

Status & tagging log