|
|
2b8996 |
|
|
|
2b8996 |
|
|
|
2b8996 |
if (!extension_loaded("memcache")) {
|
|
|
2b8996 |
die("skip");
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
error_reporting(E_ALL);
|
|
|
2b8996 |
|
|
|
2b8996 |
/*
|
|
|
2b8996 |
* Please change host & port to match your configuration
|
|
|
2b8996 |
*/
|
|
|
2b8996 |
|
|
|
2b8996 |
$host = "localhost";
|
|
|
2b8996 |
$port = 11211;
|
|
|
2b8996 |
$udpPort = 11211;
|
|
|
2b8996 |
|
|
|
2b8996 |
$host2 = "localhost";
|
|
|
2b8996 |
$port2 = 11212;
|
|
|
2b8996 |
$udpPort2 = 11212;
|
|
|
2b8996 |
|
|
|
2b8996 |
//ini_set('memcache.hash_strategy', 'standard');
|
|
|
2b8996 |
//ini_set('memcache.hash_function', 'fnv');
|
|
|
2b8996 |
//ini_set('memcache.protocol', 'binary');
|
|
|
2b8996 |
|
|
|
2b8996 |
if (ini_get('memcache.protocol') == 'binary') {
|
|
|
2b8996 |
$udpPort = 0;
|
|
|
2b8996 |
$udpPort2 = 0;
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
/* Start a server listening to a unix domain socket
|
|
|
2b8996 |
*
|
|
|
2b8996 |
* mkdir /var/run/memcached
|
|
|
2b8996 |
* chown memcached:memcached /var/run/memcached
|
|
|
2b8996 |
* memcached -d -u memcached -s /var/run/memcached/memcached.sock
|
|
|
2b8996 |
* chmod a+w /var/run/memcached/memcached.sock
|
|
|
2b8996 |
*/
|
|
|
2b8996 |
$domainsocket = 'unix:///var/run/memcached/memcached.sock';
|
|
|
2b8996 |
|
|
|
2b8996 |
// A server which is guaranteed to fail immediatly
|
|
|
2b8996 |
$nonExistingHost = "localhost";
|
|
|
2b8996 |
$nonExistingPort = 11213;
|
|
|
2b8996 |
|
|
|
2b8996 |
// A server which times out when attempting to connect to
|
|
|
2b8996 |
$unreachableHost = '10.254.254.254';
|
|
|
2b8996 |
$unreachablePort = 11211;
|
|
|
2b8996 |
|
|
|
2b8996 |
$udpPacketSize = 1400;
|
|
|
2b8996 |
|
|
|
2b8996 |
$balanceKeys = array(
|
|
|
2b8996 |
'consistent' => array(
|
|
|
2b8996 |
'crc32' => array('key1_abc', 'key2_abcde'),
|
|
|
2b8996 |
'fnv' => array('key1_a', 'key2_2534534'),
|
|
|
2b8996 |
),
|
|
|
2b8996 |
'standard' => array(
|
|
|
2b8996 |
'crc32' => array('load_test_key1', 'load_test_key2'),
|
|
|
2b8996 |
'fnv' => array('key1_ab', 'key2_a'),
|
|
|
2b8996 |
),
|
|
|
2b8996 |
);
|
|
|
2b8996 |
|
|
|
2b8996 |
$strat = strtolower(ini_get('memcache.hash_strategy'));
|
|
|
2b8996 |
$func = strtolower(ini_get('memcache.hash_function'));
|
|
|
2b8996 |
list ($balanceKey1, $balanceKey2) = $balanceKeys[$strat][$func];
|
|
|
2b8996 |
|
|
|
2b8996 |
if (!isset($udpPort))
|
|
|
2b8996 |
$udpPort = 0;
|
|
|
2b8996 |
if (!isset($udpPort2))
|
|
|
2b8996 |
$udpPort2 = 0;
|
|
|
2b8996 |
|
|
|
2b8996 |
$memcache = memcache_connect($host, $port);
|
|
|
2b8996 |
|
|
|
2b8996 |
function test_connect1() {
|
|
|
2b8996 |
global $host, $port, $udpPort;
|
|
|
2b8996 |
$memcache = new MemcachePool();
|
|
|
2b8996 |
$memcache->connect($host, $port, isset($udpPort) ? $udpPort : 0);
|
|
|
2b8996 |
return $memcache;
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
function test_connect2() {
|
|
|
2b8996 |
global $host2, $port2, $udpPort2;
|
|
|
2b8996 |
$memcache = new MemcachePool();
|
|
|
2b8996 |
$memcache->connect($host2, $port2, isset($udpPort2) ? $udpPort2 : 0);
|
|
|
2b8996 |
return $memcache;
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
function test_connect_pool() {
|
|
|
2b8996 |
global $host, $port, $udpPort, $host2, $port2, $udpPort2;
|
|
|
2b8996 |
$memcache = new MemcachePool();
|
|
|
2b8996 |
$memcache->addServer($host, $port, isset($udpPort) ? $udpPort : 0);
|
|
|
2b8996 |
$memcache->addServer($host2, $port2, isset($udpPort2) ? $udpPort2 : 0);
|
|
|
2b8996 |
return $memcache;
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
if (!$memcache) {
|
|
|
2b8996 |
die('skip Connection to memcached failed');
|
|
|
2b8996 |
}
|
|
|
2b8996 |
|
|
|
2b8996 |
?>
|