Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • FileSystem
  • HttpResponse
  • Imap
  • JsonRpc
  • Memcached
  • Mysql
  • Pgsql
  • PhpExtension
  • PhpVersion
  • PhpZend
  • Smtp
  • Webdav
  • XmlRpc
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: namespace Jyxo\Beholder\TestCase;
 15: 
 16: /**
 17:  * Tests memcache availability.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\Beholder
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Jaroslav HanslĂ­k
 24:  */
 25: class Memcached extends \Jyxo\Beholder\TestCase
 26: {
 27:     /**
 28:      * Server ip address.
 29:      *
 30:      * @var string
 31:      */
 32:     private $ip;
 33: 
 34:     /**
 35:      * Port.
 36:      *
 37:      * @var integer
 38:      */
 39:     private $port;
 40: 
 41:     /**
 42:      * Constructor.
 43:      *
 44:      * @param string $description Test description
 45:      * @param string $ip Server address
 46:      * @param integer $port Port
 47:      */
 48:     public function __construct($description, $ip, $port)
 49:     {
 50:         parent::__construct($description);
 51: 
 52:         $this->ip = (string) $ip;
 53:         $this->port = (int) $port;
 54:     }
 55: 
 56:     /**
 57:      * Performs the test.
 58:      *
 59:      * @return \Jyxo\Beholder\Result
 60:      */
 61:     public function run()
 62:     {
 63:         // The memcache extension is required
 64:         if (!extension_loaded('memcache')) {
 65:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension memcache missing');
 66:         }
 67: 
 68:         $random = md5(uniqid(time(), true));
 69:         $key = 'beholder-' . $random;
 70:         $value = $random;
 71: 
 72:         // Status label
 73:         $description = gethostbyaddr($this->ip) . ':' . $this->port;
 74: 
 75:         // Connection
 76:         $memcache = new \Memcache();
 77:         if (false === $memcache->connect($this->ip, $this->port)) {
 78:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Connection error %s', $description));
 79:         }
 80: 
 81:         // Saving
 82:         if (false === $memcache->set($key, $value)) {
 83:             $memcache->close();
 84:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Write error %s', $description));
 85:         }
 86: 
 87:         // Check
 88:         $check = $memcache->get($key);
 89:         if ((false === $check) || ($check !== $value)) {
 90:             $memcache->close();
 91:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Read error %s', $description));
 92:         }
 93: 
 94:         // Deleting
 95:         if (false === $memcache->delete($key)) {
 96:             $memcache->close();
 97:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Delete error %s', $description));
 98:         }
 99: 
100:         $memcache->close();
101: 
102:         // OK
103:         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description);
104:     }
105: }
106: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0