public function __construct(array $configs)
 {
     foreach ($configs as $name => $config) {
         $check = new Memcache($config['host'], $config['port']);
         $check->setLabel(sprintf('Memcache "%s"', $name));
         $this->checks[sprintf('memcache_%s', $name)] = $check;
     }
 }
示例#2
0
 /**
  * @see ZendDiagnostics\CheckInterface::check()
  */
 public function check()
 {
     if (!class_exists('Memcache', false)) {
         return new Failure('Memcache extension is not loaded');
     }
     try {
         $memcache = new \Memcache();
         $memcache->addServer($this->host, $this->port);
         $stats = @$memcache->getExtendedStats();
         if (!$stats || !is_array($stats) || !isset($stats[$this->host . ':' . $this->port]) || $stats[$this->host . ':' . $this->port] === false) {
             // Attempt a connection to make sure that the server is really down
             if (!@$memcache->connect($this->host, $this->port)) {
                 return new Failure(sprintf('No memcache server running at host %s on port %s', $this->host, $this->port));
             }
         }
     } catch (\Exception $e) {
         return new Failure($e->getMessage());
     }
     return new Success(sprintf('Memcache server running at host %s on port %s', $this->host, $this->port));
 }