When saving preferences, check hook and authentication plugin, and actually save...
[mediawiki.git] / docs / memcached.txt
blob3addd965c28e912497b313f39d67b0cb115b6b54
1 memcached support for MediaWiki:
3 From ca August 2003, MediaWiki has optional support for memcached, a
4 "high-performance, distributed memory object caching system".
5 For general information on it, see: http://www.danga.com/memcached/
7 Memcached is likely more trouble than a small site will need, but
8 for a larger site with heavy load, like Wikipedia, it should help
9 lighten the load on the database servers by caching data and objects
10 in memory.
12 == Requirements ==
14 * PHP must be compiled with --enable-sockets
16 * libevent: http://www.monkey.org/~provos/libevent/
17   (as of 2003-08-11, 0.7a is current)
19 * optionally, epoll-rt patch for Linux kernel:
20   http://www.xmailserver.org/linux-patches/nio-improve.html
22 * memcached: http://www.danga.com/memcached/download.bml
23   (as of this writing, 1.1.9 is current)
24   
25 Memcached and libevent are under BSD-style licenses.
27 The server should run on Linux and other Unix-like systems... you
28 can run multiple servers on one machine or on multiple machines on
29 a network; storage can be distributed across multiple servers, and
30 multiple web servers can use the same cache cluster.
32 ********************* W A R N I N G ! ! ! ! ! ***********************
33 Memcached has no security or authentication. Please ensure that your
34 server is appropriately firewalled, and that the port(s) used for
35 memcached servers are not publicly accessible. Otherwise, anyone on
36 the internet can put data into and read data from your cache.
38 An attacker familiar with MediaWiki internals could use this to give
39 themselves developer access and delete all data from the wiki's
40 database, as well as getting all users' password hashes and e-mail
41 addresses.
42 ********************* W A R N I N G ! ! ! ! ! ***********************
44 == Setup ==
46 If you want to start small, just run one memcached on your web
47 server:
49   memcached -d -l 127.0.0.1 -p 11000 -m 64
51 (to run in daemon mode, accessible only via loopback interface,
52 on port 11000, using up to 64MB of memory)
54 In your LocalSettings.php file, set:
56         $wgMainCacheType = CACHE_MEMCACHED;
57         $wgMemCachedServers = array( "127.0.0.1:11000" );
59 The wiki should then use memcached to cache various data. To use
60 multiple servers (physically separate boxes or multiple caches
61 on one machine on a large-memory x86 box), just add more items
62 to the array. To increase the weight of a server (say, because
63 it has twice the memory of the others and you want to spread
64 usage evenly), make its entry a subarray:
66   $wgMemCachedServers = array(
67     "127.0.0.1:11000", # one gig on this box
68     array("192.168.0.1:11000", 2 ) # two gigs on the other box
69   );
71 == PHP client for memcached ==
73 As of this writing, MediaWiki includes version 1.0.10 of the PHP
74 memcached client by Ryan Gilfether <hotrodder@rocketmail.com>.
75 You'll find some documentation for it in the 'php-memcached'
76 subdirectory under the present one.
78 We intend to track updates, but if you want to check for the lastest
79 released version, see http://www.danga.com/memcached/apis.bml
81 If you don't set $wgUseMemCached, we still create a MemCacheClient,
82 but requests to it are no-ops and we always fall through to the
83 database. If the cache daemon can't be contacted, it should also
84 disable itself fairly smoothly.
86 == Keys used ==
88 User:
89         key: $wgDBname:user:id:$sId
90         ex: wikidb:user:id:51
91         stores: instance of class User
92         set in: User::loadFromSession()
93         cleared by: User::saveSettings(), UserTalkUpdate::doUpdate()
94         
95 Newtalk:
96         key: $wgDBname:newtalk:ip:$ip
97         ex: wikidb:newtalk:ip:123.45.67.89
98         stores: integer, 0 or 1
99         set in: User::loadFromDatabase()
100         cleared by: User::saveSettings() # ?
101         expiry set to 30 minutes
103 LinkCache:
104         key: $wgDBname:lc:title:$title
105         ex: wikidb:lc:title:Wikipedia:Welcome,_Newcomers!
106         stores: cur_id of page, or 0 if page does not exist
107         set in: LinkCache::addLink()
108         cleared by: LinkCache::clearBadLink()
109                 should be cleared on page deletion and rename
110 MediaWiki namespace:
111         key: $wgDBname:messages
112         ex: wikidb:messages
113         stores: an array where the keys are DB keys and the values are messages
114         set in: wfMsg(), Article::editUpdates() both call wfLoadAllMessages()
115         cleared by: nothing
117 Watchlist:
118         key: $wgDBname:watchlist:id:$userID
119         ex: wikidb:watchlist:id:4635
120         stores: HTML string
121         cleared by: nothing, expiry time $wgWLCacheTimeout (1 hour)
122         note: emergency optimisation only
124 IP blocks:
125         key: $wgDBname:ipblocks
126         ex: wikidb:ipblocks
127         stores: array of arrays, for the BlockCache class
128         cleared by: BlockCache:clear()
129         
130 ... more to come ...