View source
<?php
define('WATCHDOG_ERROR', 2);
function variable_get($name, $default) {
return $default;
}
function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
}
include_once './includes/memcache.inc';
print "<h1>Memcache configuration details</h1>";
print "<ul><li>memcache.allow_failover=" . ini_get('memcache.allow_failover') . "</li>";
print "<li>memcache.max_failover_attempts=" . ini_get('memcache.max_failover_attempts') . "</li>";
print "<li>memcache.chunk_size=" . ini_get('memcache.chunk_size') . "</li>";
print "<li>memcache.default_port=" . ini_get('memcache.default_port') . "</li>";
print "</ul>";
global $conf;
printHeader();
$mc = dmemcache_object();
formatStats($mc
->getStats());
$mc
->close();
unset($mc);
printHeader();
$mc = dmemcache_object();
$keys = array(
'a',
time(),
'http://www.robshouse.net/home/page?q=xyz&p=x',
'What about space?',
);
print '<ol>';
foreach ($keys as $key) {
testKeyValue($mc, $key, 'Hi Robert');
}
print '</ol>';
$mc
->close();
unset($mc);
printHeader();
$mc = dmemcache_object();
print '<ol>';
$key = ' ';
testKeyValue($mc, $key, 'Hi Dude');
$key = "\n";
testKeyValue($mc, $key, 'Hi Dude 2');
print '<li><em>space and line break different?</em>=' . $mc
->get(' ') . '</li>';
print '</ol>';
$mc
->close();
unset($mc);
printHeader();
$mc = dmemcache_object();
formatStats($mc
->getStats());
unset($conf['memcache']);
$conf['memcache'][] = array(
'#servers' => array(
'localhost:11212',
),
'#bins' => array(
'default',
),
);
$mc
->close();
unset($mc);
$mc = dmemcache_object('default', TRUE);
formatStats($mc
->getStats());
$mc
->close();
unset($mc);
printHeader();
$mc = dmemcache_object();
$mc
->set("\n", "This is a new line", FALSE, 5);
print '<ol>';
print '<li>' . $mc
->get("\n") . '</li>';
print '<li>' . $mc
->get(" ") . '</li>';
print '</ol>';
$mc
->close();
unset($mc);
printHeader();
$keys = array(
'a',
time(),
'http://www.robshouse.net/home/page?q=xyz&p=x',
'What about space?',
);
print '<ol>';
foreach ($keys as $key) {
dtestKeyValue($key, 'Hi Robert 2');
}
print '</ol>';
printHeader();
dmemcache_set("\n", "This is a new line");
print '<ol>';
print '<li>' . dmemcache_get("\n") . '</li>';
print '<li>' . dmemcache_get(" ") . '</li>';
print '</ol>';
printHeader();
unset($conf['memcache']);
$conf['memcache'][] = array(
'#servers' => array(
'localhost:11211',
'localhost:11212',
),
'#bins' => array(
'default',
),
);
dmemcache_object('default', TRUE);
$mc1 = new Memcache();
$mc1
->connect('localhost', 11211);
$mc2 = new Memcache();
$mc2
->connect('localhost', 11212);
$last_key = $last_value = '';
$time = microtime();
for ($i = 1; $i < 10001; $i++) {
$last_key = $time . $i . 'key';
$last_value = 'Some very random thoughts about things in general' . $time;
dmemcache_set($last_key, $last_value, FALSE, 0);
if ($i % 1000 == 1) {
formatStats2($mc1, $mc2);
flush();
}
}
print "</table>";
printHeader();
formatStats2($mc1, $mc2, TRUE);
print "</table>";
dmemcache_flush();
formatStats2($mc1, $mc2, TRUE);
print "</table>";
printHeader();
print "<pre>";
$types = array(
'reset',
'malloc',
'maps',
'slabs',
'items',
'sizes',
);
foreach ($types as $type) {
print "<h2>{$type}</h2>";
print "<h3>Server 1</h3>";
print_r($mc1
->getExtendedStats($type));
print "<h3>Server 2</h3>";
print_r($mc2
->getExtendedStats($type));
}
print "</pre>";
$mc1
->close();
$mc2
->close();
unset($mc1);
unset($mc2);
printHeader();
dmemcache_set('delete me', 'Goodbye world');
print "<h2>" . dmemcache_get('delete me') . "</h2>";
dmemcache_delete('delete me');
print "<h2>Nothing here ---->" . dmemcache_get('delete me') . "<--</h2>";
printHeader();
$mc1 = new Memcache();
$mc1
->connect('localhost', 11211);
$mc2 = new Memcache();
$mc2
->connect('localhost', 11212);
unset($conf['memcache']);
$conf['memcache'][] = array(
'#servers' => array(
'localhost:11211',
),
'#bins' => array(
'default',
'antwerp',
),
);
$conf['memcache'][] = array(
'#servers' => array(
'localhost:11212',
),
'#bins' => array(
'vancouver',
'barcelona',
),
);
dmemcache_object('', TRUE);
$first = TRUE;
print "<h3>Bin: default</h3>";
$last_key = $last_value = '';
$time = microtime();
for ($i = 1; $i < 10001; $i++) {
$last_key = $time . $i . 'key';
$last_value = 'default ' . $i;
dmemcache_set($last_key, $last_value, 20, 'default');
if ($i % 1000 == 1) {
$cluster = dmemcache_object('default');
print_r($cluster);
formatStats2($mc1, $mc2, $first);
$first = FALSE;
flush();
$keyin_keyout[] = array(
'orig' => $last_value,
'cache' => dmemcache_get($last_key, 'default'),
);
}
}
print "</table>";
print "<h4>Values for default</h4>";
print '<table border="1"><tr><th>Original</th><th>Cached</th></tr>';
foreach ($keyin_keyout as $values) {
print "<tr><td>" . $values['orig'] . "</td><td>" . $values['cache'] . "</td></tr>";
}
print "</table>";
print "<h3>Bin: vancouver</h3>";
$first = TRUE;
$keyin_keyout = array();
$last_key = $last_value = '';
$time = microtime();
for ($i = 1; $i < 10001; $i++) {
$last_key = $time . $i . 'key';
$last_value = 'vancouver ' . $i;
dmemcache_set($last_key, $last_value, 20, 'vancouver');
if ($i % 1000 == 1) {
$cluster = dmemcache_object('vancouver');
print_r($cluster);
formatStats2($mc1, $mc2, $first);
$first = FALSE;
flush();
$keyin_keyout[] = array(
'orig' => $last_value,
'cache' => dmemcache_get($last_key, 'vancouver'),
);
}
}
print "</table>";
print "<h4>Values for vancouver</h4>";
print '<table border="1"><tr><th>Original</th><th>Cached</th></tr>';
foreach ($keyin_keyout as $values) {
print "<tr><td>" . $values['orig'] . "</td><td>" . $values['cache'] . "</td></tr>";
}
print "</table>";
print "<h3>Bin: barcelona</h3>";
$first = TRUE;
$keyin_keyout = array();
$last_key = $last_value = '';
$time = microtime();
for ($i = 1; $i < 10001; $i++) {
$last_key = $time . $i . 'key';
$last_value = 'barcelona ' . $i;
dmemcache_set($last_key, $last_value, 20, 'barcelona');
if ($i % 1000 == 1) {
$cluster = dmemcache_object('barcelona');
print_r($cluster);
formatStats2($mc1, $mc2, $first);
$first = FALSE;
flush();
$keyin_keyout[] = array(
'orig' => $last_value,
'cache' => dmemcache_get($last_key, 'barcelona'),
);
}
}
print "</table>";
print "<h4>Values for barcelona</h4>";
print '<table border="1"><tr><th>Original</th><th>Cached</th></tr>';
foreach ($keyin_keyout as $values) {
print "<tr><td>" . $values['orig'] . "</td><td>" . $values['cache'] . "</td></tr>";
}
print "</table>";
print "<h3>Bin: antwerp</h3>";
$first = TRUE;
$keyin_keyout = array();
$last_key = $last_value = '';
$time = microtime();
for ($i = 1; $i < 10001; $i++) {
$last_key = $time . $i . 'key';
$last_value = 'antwerp ' . $i;
dmemcache_set($last_key, $last_value, 20, 'antwerp');
if ($i % 1000 == 1) {
$cluster = dmemcache_object('antwerp');
print_r($cluster);
formatStats2($mc1, $mc2, $first);
$first = FALSE;
flush();
$keyin_keyout[] = array(
'orig' => $last_value,
'cache' => dmemcache_get($last_key, 'antwerp'),
);
}
}
print "</table>";
print "<h4>Values for antwerp</h4>";
print '<table border="1"><tr><th>Original</th><th>Cached</th></tr>';
foreach ($keyin_keyout as $values) {
print "<tr><td>" . $values['orig'] . "</td><td>" . $values['cache'] . "</td></tr>";
}
print "</table>";
$mc1
->close();
$mc2
->close();
unset($mc1);
unset($mc2);
printHeader();
function testKeyValue($mc, $key, $value) {
$mc
->set($key, $value, FALSE, 5);
printKeyValue($key, $mc
->get($key));
}
function dtestKeyValue($key, $value, $bin = 'default') {
dmemcache_set($key, $value, 5, $bin);
printKeyValue($key, dmemcache_get($key));
}
function printKeyValue($key, $value) {
print '<li>' . $key . '=' . $value . '</li>';
}
function formatStats($stats = array()) {
print '<ul>';
foreach ($stats as $name => $value) {
print '<li>' . $name . '=' . $value . '</li>';
}
print '</ul>';
}
function printHeader() {
static $count = 1;
print "<a name='{$count}'><h2>Test " . $count++ . "</h2></a>";
}
function formatStats2($mc1, $mc2, $flush = FALSE) {
static $count, $first;
$stats1 = $mc1
->getStats();
$stats2 = $mc2
->getStats();
if ($flush) {
unset($first);
}
if (!isset($first)) {
$count = 1;
$first = FALSE;
print "<table border='1'><tr><th> </th><th>Server 1</th><th>Server 2</th></tr>";
}
print "<tr><td>{$count}</td><td>" . $stats1['bytes'] . "</td><td>" . $stats2['bytes'] . "</td></tr>";
$count++;
}