1

Having issues using the PHP memcached class.

I am running a LAMP environment on Ubuntu 10.10 with Apache 2.2.16 and PHP 5.3.3. I have just installed what I thought was memcached, but seems possibly to be memcache?

I can start a new memcache object with:

$m = new Memcache;

Which works fine. But when I try and start a memcached object

$m = new Memcached();

I get the following error

Fatal error: Class 'Memcached' not found

When I run 'ps -A | grep Memcache' through the console, it returns

ben@ben-computer:/tmp$ ps -A | grep memcache
1214 ?        00:00:00 memcached

Showing a running memcached process. phpinfo() returns memcache version 2.2.6.

But when I look further into etc folder

ben@ben-computer:/etc/default$ cat memcached 
# Set this to no to disable memcached.
ENABLE_MEMCACHED=yes

Then when i run php -m it returns memcache.

You kind of get the picture, i have no idea why memcache is running instead of memcached, any help would be great.

Edit:

I think it could be an issue with libmemcached. I installed the libmemcached-dev package, but not sure if that's the same?

Ben
  • 104
  • 1
  • 10
  • @hakre, there is a PHP class called Memcached as well. – Ben Oct 05 '11 at 17:57
  • The classname is called [`Memcache`](http://www.php.net/manual/en/class.memcache.php) or are you using a different extension? Like [`Memcached`](http://www.php.net/manual/en/class.memcached.php)? You then need to install the *Memcached* extension, not the *Memcache* extension. – hakre Oct 05 '11 at 18:01

3 Answers3

2

Memcache = name of class
Memcached = name of daemon that runs class

Similarly, cron and crond, mysql and mysqld.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • 1
    But PHP have a whole section on the Memcached class http://uk.php.net/manual/en/class.memcached.php, the one I'm trying to use. – Ben Oct 05 '11 at 17:54
2

There are two different PHP classes that you can use. I recommend memcached over memcache because it is newer and supports more features.

Community
  • 1
  • 1
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
  • Thank you Xeoncross, there are two different classes. I want to use the Memcached class but can only use the Memcache class. Any ideas why it might not work? – Ben Oct 05 '11 at 17:57
  • @Ben, you need to install it. Read the [memcached installation guide](http://us3.php.net/manual/en/memcached.setup.php) to see how. – Xeoncross Oct 05 '11 at 17:58
1

The memcached extension is not a standard component of PHP, and must be installed separately from PECL. Instructions are online at:

http://php.net/memcached.installation