我刚刚在OS X Mountain Lion上的XAMPP中安装了Memcache,我正在尝试使用它来运行它:
$memcache = new Memcache();
$memcache>connect('127.0.0.1', 11211) or die ("Could not connect");
返回:
Fatal error: Class 'Memcache' not found in /Applications/XAMPP/xamppfiles/htdocs/mysite/myfile.php on line 123
我该怎么做才能解决这个问题?
我使用this guide
安装了Memcache在我的php.ini文件中,我有extension="memcache.so"
在phpinfo.php中我有mod_mem_cache
答案 0 :(得分:1)
首先,检查您的语法是否正确。 您在提交的示例代码中缺少指针。 “ - >” 中。 此外,我无法通过使用“或死”来检查连接是否成功, 因此我经常检查连接对象本身。
$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211);
if ($memcache === FALSE){
echo 'Unable to connect to memcache';
}
如果这不起作用,那么检查一下你确实有memcache可用。 在OSX上打开终端并运行:
php --info | grep '^memcache'