1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: namespace Jyxo\Beholder\TestCase;
15:
16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class Memcached extends \Jyxo\Beholder\TestCase
26: {
27: 28: 29: 30: 31:
32: private $ip;
33:
34: 35: 36: 37: 38:
39: private $port;
40:
41: 42: 43: 44: 45: 46: 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: 58: 59: 60:
61: public function run()
62: {
63:
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:
73: $description = gethostbyaddr($this->ip) . ':' . $this->port;
74:
75:
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:
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:
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:
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:
103: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description);
104: }
105: }
106: