include 'php/db.php';
$qry = "select * from dsb_online";
$result = mysql_query($qry,$link);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result)) {
$s=array($row['fk_user_id'],$row['last_activity']);
}
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$memcache->set('key', $s, false, 10) or
die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)
<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
我已经在我的 xampp 中安装了 memcached。这是我正在运行以测试它的测试文件。我得到的输出是
Server's version: 1.2.6
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
array(2) { [0]=> string(1) "3" [1]=> string(19) "2013-02-11 11:54:44" }
现在我修改了这样的代码来测试是否从 memcached 中检索到数据
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
结果是
Server's version: 1.2.6
Data from the cache:
bool(false)
谁能告诉我为什么我的缓存不起作用