tags:

views:

28

answers:

2

If I run phpinfo() it tells me that memcached is installed.

memcached
memcached support   enabled
Version     1.0.2
libmemcached version    0.44
Session support     yes
igbinary support    no 

I installed it with sudo pecl install memcached

But when I try to instantiate the memcached class it is not found:

$mc = new Memcached();

gets:

Fatal error: Class 'Memcached' not found

Never used PECL as an install mechanism before, do I need to do something extra in php.ini or somewhere to be able to use the class?

+1  A: 

It's possible that it didn't install correctly or, as you say, you might need to add the following to php.ini: extension = memcached.so

But since you say it shows up in phpinfo() it seems more likely that it just didn't install correctly. Were there any errors in the output during installation?

Also, to state the obvious, make sure you've restarted your server.

I wrote up a tutorial on getting memcached running on Ubuntu, which I mention not to self-promote, but just in case it's helpful.

stevelove
Just checked out your very helpful blog post. Are you saying that the last version of libmemcached to work on Ubuntu 9.04 is 0.33 or can I go newer?
Steve Claridge
At the time of that post's original publication date a year ago, the highest version of libmemcached I could get working on Ubuntu 9.04 was 0.33. Newer versions may work, but you may just need to try them one at a time till you find one that does. Wish I could give you a better answer than that.
stevelove
libmemcached-0.44 and "sudo pecl install memcached" worked fine on Ubuntu 9.04. No build errors.
Steve Claridge
Found my problem, rather embarrassing: I added extension=memcached.so to php.ini inside /etc/php5/apache but didn't update the one in /etc/php5/cli and I was running a test script from the cli. duh.
Steve Claridge
Glad you got it sorted! :)
stevelove
A: 

Use new Memcache(); not new Memcached();. This class is named Memcache without d at the end.

Svisstack
There's two PHP extensions for talking to a memcached server - one called memcache and one called memcached. Check out the link in the top line of the question, it's Memcached()
Steve Claridge