Memcached installed (In theory), PHP unable to use memcache_connect()

11,492

Solution 1

You installed the Memcached client (not the Memcache client, which is, very confusingly, also a Memcached client). Use the Memcached class instead.

In case you're wondering what the difference between the two clients is: here's a nice comparison table.

Solution 2

It looks like you still need pecl/memcache or pecl/memcached (Client/php end)

pecl/memcached will use libmemcached.

pecl/memcache doesn't have that dependency.

Some of notes on how to install pecl/memcached
Yum install:
   * memcached
   * memcached-devel
   * php-pear
   * php-devel
   * gcc
   * gcc-c++
   * zlib-devel

Download libmemcached from: http://download.tangent.org/
Configure, Make, Make  install
pecl install memcached
added "extension=memcached.so" to php.ini
Share:
11,492

Related videos on Youtube

Jonathan
Author by

Jonathan

A web programmer and developer based out of Calgary, Alberta. Looking to learn, and help where I can.

Updated on May 19, 2022

Comments

  • Jonathan
    Jonathan about 2 years

    Just finished installing libevent(1.4.8), memcached(1.4.5), pear, and libmemcached(0.40) to my lamp server (running PHP 5.2.10 & Centos 5.5 Final), and as far as I can tell, everything installed correctly (was able to address all errors during installation).

    However, after finally getting everything updated and installed... upon attempting either of the following:

    $test=memcache_connect('127.0.0.1', 11211); // OR
    
    $memcache = new Memcache;
    $memcache->connect('127.0.0.1', 11211) 
    

    I get the errors:

    Fatal error: Class 'Memcache' not found (or) Fatal error: Call to undefined function memcache_connect()

    I'm (admittedly) not very good with linux at this point, although after setting this server up completely from scratch, i'm certainly making headway in the education process :) Any help would be much appreciated!

    phpinfo() Shows memcached is enabled

  • Jonathan
    Jonathan over 13 years
    Oh my gosh... thank you! I am temporarily more confused, however php.net/manual/en/class.memcached.php](http://php.net/manual‌​/en/… has helped a great deal so far. Correct me if i'm wrong, but it seems that memcached replaces memcache? Or are they completely separate? Either way, thank you for your help!
  • Jonathan
    Jonathan over 13 years
    Thank you! This, along with Victor's answer helped me figure it out. $mc=new Memcached; worked perfectly. Thanks again!
  • Victor Welling
    Victor Welling over 13 years
    It's not really a replacement, just a different approach to implementing a PHP client for Memcached. Depending on your needs, you can use either client.