コード例 #1
0
ファイル: mctest.php プロジェクト: claudinec/galan-wiki
 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);
     }
 }
コード例 #2
0
 public function add($key, $value, $exptime = 0)
 {
     return $this->client->add($this->validateKeyEncoding($key), $value, $this->fixExpiry($exptime));
 }
コード例 #3
0
 public function changeTTL($key, $exptime = 0)
 {
     return $this->client->touch($this->validateKeyEncoding($key), $this->fixExpiry($exptime));
 }
コード例 #4
0
ファイル: mcc.php プロジェクト: claudinec/galan-wiki
 *
 * @file
 * @todo document
 * @ingroup Maintenance
 */
$optionsWithArgs = ['cache'];
$optionsWithoutArgs = ['debug', 'help'];
require_once __DIR__ . '/commandLine.inc';
$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);
}
/**