Index: trunk/phase3/docs/memcached.doc |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | |
74 | 74 | == PHP client for memcached == |
75 | 75 | |
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 |
77 | 77 | memcached client by Ryan Gilfether <hotrodder@rocketmail.com>. |
78 | 78 | You'll find some documentation for it in the 'php-memcached' |
79 | 79 | subdirectory under the present one. |
— | — | @@ -88,15 +88,23 @@ |
89 | 89 | == Keys used == |
90 | 90 | |
91 | 91 | 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 |
94 | 94 | stores: instance of class User |
95 | 95 | 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 |
97 | 105 | |
98 | 106 | 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! |
101 | 109 | stores: cur_id of page, or 0 if page does not exist |
102 | 110 | set in: LinkCache::addLink() |
103 | 111 | 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 | + |
2 | 11 | Release 1.0.8 |
3 | 12 | ------------- |
4 | 13 | * whitespace/punctuation/wording cleanups |
Index: trunk/phase3/docs/php-memcached/Documentation |
— | — | @@ -158,8 +158,9 @@ |
159 | 159 | MC_ERR_LOADITEM_BYTES // _load_items bytes read larger than bytes available |
160 | 160 | MC_ERR_GET // failed to get value associated with key |
161 | 161 | |
| 162 | +// Turns compression on or off; 0=off, 1=on |
| 163 | +MemCacheClient::set_compression($setting) |
162 | 164 | |
163 | | - |
164 | 165 | EXAMPLE: |
165 | 166 | <?php |
166 | 167 | require("MemCachedClient.inc.php"); |
Index: trunk/phase3/includes/MemCachedClient.inc.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | /** |
21 | 21 | * version string |
22 | 22 | */ |
23 | | -define("MC_VERSION", "1.0.9"); |
| 23 | +define("MC_VERSION", "1.0.10"); |
24 | 24 | /** |
25 | 25 | * int, buffer size used for sending and receiving |
26 | 26 | * data from sockets |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | * @author Ryan Gilfether <ryan@gilfether.com> |
53 | 53 | * @package MemCachedClient |
54 | 54 | * @access public |
55 | | - * @version 1.0.7 |
| 55 | + * @version 1.0.10 |
56 | 56 | */ |
57 | 57 | class MemCachedClient |
58 | 58 | { |
— | — | @@ -90,8 +90,24 @@ |
91 | 91 | * @var string |
92 | 92 | */ |
93 | 93 | 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; |
94 | 104 | |
| 105 | + /** |
| 106 | + * array that contains parsed out buckets |
| 107 | + * @ var array |
| 108 | + */ |
| 109 | + var $bucket; |
95 | 110 | |
| 111 | + |
96 | 112 | /** |
97 | 113 | * Constructor |
98 | 114 | * |
— | — | @@ -116,6 +132,7 @@ |
117 | 133 | { |
118 | 134 | $this->set_servers($options["servers"]); |
119 | 135 | $this->debug = $options["debug"]; |
| 136 | + $this->compress = $options["compress"]; |
120 | 137 | $this->cache_sock = array(); |
121 | 138 | } |
122 | 139 | |
— | — | @@ -550,6 +567,23 @@ |
551 | 568 | } |
552 | 569 | |
553 | 570 | |
| 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 | + |
554 | 588 | /* |
555 | 589 | * PRIVATE FUNCTIONS |
556 | 590 | */ |
— | — | @@ -637,8 +671,6 @@ |
638 | 672 | */ |
639 | 673 | function get_sock($key) |
640 | 674 | { |
641 | | - $buckets = 0; |
642 | | - |
643 | 675 | if(!$this->active) |
644 | 676 | { |
645 | 677 | $this->errno = MC_ERR_NOT_ACTIVE; |
— | — | @@ -652,9 +684,9 @@ |
653 | 685 | |
654 | 686 | $hv = is_array($key) ? intval($key[0]) : $this->_hashfunc($key); |
655 | 687 | |
656 | | - if(!$buckets) |
| 688 | + if(!$this->buckets) |
657 | 689 | { |
658 | | - $bu = $buckets = array(); |
| 690 | + $bu = $this->buckets = array(); |
659 | 691 | |
660 | 692 | foreach($this->servers as $v) |
661 | 693 | { |
— | — | @@ -667,14 +699,14 @@ |
668 | 700 | $bu[] = $v; |
669 | 701 | } |
670 | 702 | |
671 | | - $buckets = $bu; |
| 703 | + $this->buckets = $bu; |
672 | 704 | } |
673 | 705 | |
674 | 706 | $real_key = is_array($key) ? $key[1] : $key; |
675 | 707 | $tries = 0; |
676 | 708 | while($tries < 20) |
677 | 709 | { |
678 | | - $host = @$buckets[$hv % count($buckets)]; |
| 710 | + $host = @$this->buckets[$hv % count($this->buckets)]; |
679 | 711 | $sock = $this->sock_to_host($host); |
680 | 712 | |
681 | 713 | if(is_resource($sock)) |
— | — | @@ -783,7 +815,6 @@ |
784 | 816 | return trim($retval); |
785 | 817 | } |
786 | 818 | |
787 | | - |
788 | 819 | /** |
789 | 820 | * sends the command to the server |
790 | 821 | * Possible errors set are: |
— | — | @@ -837,6 +868,17 @@ |
838 | 869 | $flags |= 1; |
839 | 870 | } |
840 | 871 | |
| 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 | + |
841 | 883 | $len = strlen($val); |
842 | 884 | if (!is_int($exptime)) |
843 | 885 | $exptime = 0; |
— | — | @@ -1034,6 +1076,8 @@ |
1035 | 1077 | |
1036 | 1078 | if(strlen($val[$sk]) != $len_array[$sk]) |
1037 | 1079 | continue; |
| 1080 | + if(@$flags_array[$sk] & 2) |
| 1081 | + $val[$sk] = gzuncompress($val[$sk]); |
1038 | 1082 | |
1039 | 1083 | if(@$flags_array[$sk] & 1) |
1040 | 1084 | $val[$sk] = unserialize($val[$sk]); |
— | — | @@ -1078,13 +1122,8 @@ |
1079 | 1123 | */ |
1080 | 1124 | function _hashfunc($num) |
1081 | 1125 | { |
1082 | | - $hash = 0; |
| 1126 | + $hash = sprintf("%u",crc32($num)); |
1083 | 1127 | |
1084 | | - foreach(preg_split('//', $num, -1, PREG_SPLIT_NO_EMPTY) as $v) |
1085 | | - { |
1086 | | - $hash = $hash * 33 + ord($v); |
1087 | | - } |
1088 | | - |
1089 | 1128 | return $hash; |
1090 | 1129 | } |
1091 | 1130 | |