我按照以下步骤在 CentOS 中安装了 memcached
这是 PHP 错误:
Fatal error: Call to a member function get() on a non-object in /home/piscolab/public_html/keepyourlinks.com/includes/funciones.php on line 22
代码:
/* MEMCACHE */
$memcache = new Memcache();
$memcache->pconnect('localhost',11211);
/* checks in memcache, if not: query and save to memcache */
function cache_query($sql,$nombre,$tiempo = -1){
if($tiempo == -1) $tiempo = time() + 24*60*60*365;
$consulta = $memcache->get($nombre); /* THIS is the line */
if ( $consulta === false) {
$consulta = mysql_query($sql);
$memcache->set($nombre,$consulta,0,$tiempo);
$_SESSION['tQ']++;
}else $_SESSION['tQC']++;
return $consulta;
}
我这样调用函数:
$result = cache_query('select * from users','all_users');
我错过了什么?