Knowledge base
1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Checking Memcached
This guide explains how to determine if Memcached is working properly on your hosting.
Prerequisites
- Install Memcached on your managed Cloud server
Check Memcached Execution
To verify that Memcached is functioning correctly
- Copy the following code into a PHP file:
// Connect to the local memcache server
$fp = fsockopen("localhost", 11211);
if ($fp) {
// Request stats
fwrite($fp, "stats\n");
while (!feof($fp)) {
$buf = rtrim(fgets($fp));
if (preg_match('/^STAT curr_items ([0-9]+)$/', $buf, $matches)) {
// Number of items stored
print $matches[1] . PHP_EOL;
} elseif (preg_match('/(END|ERROR)/', $buf)) {
// End of stats
break;
}
}
fclose($fp);
} else {
print "Error: cannot connect to local memcached server: $!" . PHP_EOL;
} - Upload the PHP file to your hosting
- Execute the PHP file
The script returns the number of items cached in the server's memory.
Link to this FAQ: