示例#1
0
 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);
     }
 }
 protected function getWithToken($key, &$casToken, $flags = 0)
 {
     return $this->client->get($this->validateKeyEncoding($key), $casToken);
 }
示例#3
0
 }
 $args = explode(' ', $line);
 $command = array_shift($args);
 // process command
 switch ($command) {
     case 'help':
         // show an help message
         print mccGetHelp(array_shift($args));
         break;
     case 'get':
         $sub = '';
         if (array_key_exists(1, $args)) {
             $sub = $args[1];
         }
         print "Getting {$args[0]}[{$sub}]\n";
         $res = $mcc->get($args[0]);
         if (array_key_exists(1, $args)) {
             $res = $res[$args[1]];
         }
         if ($res === false) {
             # print 'Error: ' . $mcc->error_string() . "\n";
             print "MemCached error\n";
         } elseif (is_string($res)) {
             print "{$res}\n";
         } else {
             var_dump($res);
         }
         break;
     case 'getsock':
         $res = $mcc->get($args[0]);
         $sock = $mcc->get_sock($args[0]);