This script allows you to check if memcache is running on the server:
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Cannot connect");
$version = $memcache->getVersion(); echo "Server version: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Error saving data to server");
echo "Data saved to cache. (data lifetime is 10 seconds)<br/>\n";
$get_result = $memcache->get('key'); echo "Data from cache:<br/>\n";
var_dump($get_result);
?>
- Instead of 127.0.0.1, insert the memcache server address or the path to the socket. Usually, 127.0.0.1 is sufficient.
- If a socket path is specified on the server, replace 11211 with 0.
Copy this script into a file named test.php, upload it to the website folder, and open it in a browser at yoursite.com/test.php
The output will look something like this:
Server version: 1.4.19
Data saved to cache. (data lifetime is 10 seconds)
Data from cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }