1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Checking Memcached is working correctly
This guide explains how to know whether Memcached is working properly on your hosting.
Prerequisites
- Install Memcached on your managed Cloud server
Checking Memcached is running
1. Copy the following code in a PHP file:
// login to the local memcache server
$fp = fsockopen("localhost", 11211);
if ($fp) {
// we are asking for the stats
fwrite($fp, "statsn");
while (!feof($fp)) {
$buf = rtrim(fgets($fp));
if (preg_match('/^STAT curr_items ([0-9]+)$/', $buf, $matches)) {
// the number of items stored
print $matches[1] . PHP_EOL;
} elseif (preg_match('/(END|ERROR)/', $buf)) {
// end of the stats
break;
}
}
fclose($fp);
} else {
print "Error: cannot connect to local memcached server: $!" . PHP_EOL;
}
2. Download the PHP file to your hosting.
3. Run the PHP file. The script sends the number of elements cached in the server memory.