public function execute() { global $wgMainCacheType, $wgMemCachedTimeout, $wgObjectCaches; $cache = $this->getOption('cache'); $iterations = $this->getOption('i', 100); if ($cache) { if (!isset($wgObjectCaches[$cache])) { $this->error("MediaWiki isn't configured with a cache named '{$cache}'", 1); } $servers = $wgObjectCaches[$cache]['servers']; } elseif ($this->hasArg()) { $servers = [$this->getArg()]; } elseif ($wgMainCacheType === CACHE_MEMCACHED) { global $wgMemCachedServers; $servers = $wgMemCachedServers; } elseif (isset($wgObjectCaches[$wgMainCacheType]['servers'])) { $servers = $wgObjectCaches[$wgMainCacheType]['servers']; } else { $this->error("MediaWiki isn't configured for Memcached usage", 1); } # find out the longest server string to nicely align output later on $maxSrvLen = $servers ? max(array_map('strlen', $servers)) : 0; foreach ($servers as $server) { $this->output(str_pad($server, $maxSrvLen), $server); $mcc = new MemcachedClient(['persistant' => true, 'timeout' => $wgMemCachedTimeout]); $mcc->set_servers([$server]); $set = 0; $incr = 0; $get = 0; $time_start = microtime(true); for ($i = 1; $i <= $iterations; $i++) { if ($mcc->set("test{$i}", $i)) { $set++; } } for ($i = 1; $i <= $iterations; $i++) { if (!is_null($mcc->incr("test{$i}", $i))) { $incr++; } } for ($i = 1; $i <= $iterations; $i++) { $value = $mcc->get("test{$i}"); if ($value == $i * 2) { $get++; } } $exectime = microtime(true) - $time_start; $this->output(" set: {$set} incr: {$incr} get: {$get} time: {$exectime}", $server); } }
$debug = isset($options['debug']); $help = isset($options['help']); $cache = isset($options['cache']) ? $options['cache'] : null; if ($help) { mccShowUsage(); exit(0); } $mcc = new MemcachedClient(['persistent' => true, 'debug' => $debug]); if ($cache) { if (!isset($wgObjectCaches[$cache])) { print "MediaWiki isn't configured with a cache named '{$cache}'"; exit(1); } $servers = $wgObjectCaches[$cache]['servers']; } elseif ($wgMainCacheType === CACHE_MEMCACHED) { $mcc->set_servers($wgMemCachedServers); } elseif (isset($wgObjectCaches[$wgMainCacheType]['servers'])) { $mcc->set_servers($wgObjectCaches[$wgMainCacheType]['servers']); } else { print "MediaWiki isn't configured for Memcached usage\n"; exit(1); } /** * Show this command line tool usage. */ function mccShowUsage() { echo <<<EOF Usage: \tmcc.php [--debug] \tmcc.php --help