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); } }