Fatal Error: class 'memcache' not found

Hi all,

When trying to use the Memcache feature, I systematically get the error mentioned in the title.

I'm using PHP5-FPM with php 5.4.9 on a Ubuntu 13.04. The memcached server, libmemcached10 and the PHP memcached extension are all installed and functional:


dpkg -l memcached*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                       Version            Architecture       Description
+++-==========================-==================-==================-===============================================
ii  memcached                  1.4.14-0ubuntu1    amd64              A high-performance memory object caching system```

```bash
dpkg -l libmemcached*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                       Version            Architecture       Description
+++-==========================-==================-==================-================================================
un  libmemcached               <none>                                (no description available)
ii  libmemcached10:amd64       1.0.8-1            amd64              C and C++ client library to the memcached server
un  libmemcached2              <none>                                (no description available)
un  libmemcached3              <none>                                (no description available)
un  libmemcached6              <none>                                (no description available)
un  libmemcached9              <none>                                (no description available)```

```bash
php5-fpm -m|grep memcache
memcached```

```bash
php5-fpm -i|grep memcache
/etc/php5/fpm/conf.d/20-memcached.ini,
memcached
memcached support => enabled
libmemcached version => 1.0.8
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
memcached.sess_binary => 0 => 0
memcached.sess_lock_wait => 150000 => 150000
memcached.sess_locking => 1 => 1
memcached.sess_prefix => memc.sess.key. => memc.sess.key.
Registered save handlers => files user memcached```

Now, the error message I get seems to indicate that Phalcon actually uses memcache and not memcache*d*.

If that's the case, must I implement my own backend memcached then?

Thanks,
Steven


12.3k

Ok I just uninstalled memcached and installed memcache, but I get the same error message... Here's where it goes wrong:


$frontCache = new \Phalcon\Cache\Frontend\Data(array(
    'lifetime' => 86400
));
$mcache = new \Phalcon\Cache\Backend\Memcache($frontCache, array(
    'host' => 'localhost',
    'port' => 11211
));
$mcache->get('some_id'); // I get the error message on this call```

So what am I doing wrong?

Thanks,
Steven


12.3k

This works, by the way (after uninstalling memcache and reinstalling memcached): ```php<?php $m = new Memcached(); $m->addServer('localhost', 11211);

$m->set('foo', 100); var_dump($m->get('foo')); // int 100```



12.3k

Ok I figured it out. Phalcon assumes the use of the (older) php5-memcache client instead of the (better) php5-memcached client. I can keep the memcached server, I just need to replace the memcached client by a memcache client.

I guess I'll need to write up a new backend, because there is none in the incubator either: https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Cache/Backend :)

If any moderator stops by, this question can be marked "closed".

Thanks, Steven



90.9k

I didn't know there was a better memcache extension, nice to know that :)



8.3k

i too have the same problem,

phalcon has no support for "memcached" but only "memcache", however its indsutry common knowlege and trend is to use the "memcached" as its more reliable than memcache extenstion it self. Plus php7 dont have support for the "memcache" only memcached is supported.

should write a new backend for memcached i guess soon.

i have it error to. it problem not resolved yet? php-7.1 via fpm. memcached installed. error on model cache set: Fatal error: Class 'memcache' not found in ... how fix it if i have memcached? @phalcon

i have it error to. it problem not resolved yet? php-7.1 via fpm. memcached installed. error on model cache set: Fatal error: Class 'memcache' not found in ... how fix it if i have memcached?