15

I am trying to connect to memcache as they suggest:

$memcache = new Memcache();
$memcache->pconnect('localhost',11211);

But i get:

Notice: Memcache::pconnect() [memcache.pconnect]: Server localhost (tcp 11211) failed with: Connection refused (111) in /home/user/public_html/website.com/includes/basedatos.php on line 26

Any idea why?

7
  • 1
    is memcahced running on your computer on port 11211?
    – dm03514
    Commented May 27, 2012 at 18:17
  • 1
    That generally means memcache isn't running. Have you set it up?
    – Amber
    Commented May 27, 2012 at 18:17
  • hm.. @Amber it seems i followed the wrong steps. my question is the second step i took from installing it via pecl, what do i need to do to set it up? Commented May 27, 2012 at 18:18
  • 2
    memcache is two parts: a client interface (the PHP version of which is installed via PECL or similar) and the actual memcache server daemon, which needs to be installed as a completely separate program or system package. What OS are you running on? If it's a debian-based flavor of Linux, try sudo apt-get install memcached
    – Amber
    Commented May 27, 2012 at 18:19
  • @Amber I see, so i am using CentOS, shall i try? and after that apt-get is there anything else i need to do? thanks a lot Commented May 27, 2012 at 18:21

3 Answers 3

23

You need to actually install the memcached server so that it can be connected to. On CentOS, this can be done with...

sudo yum install memcached

(on debian flavors of linux, use apt-get instead of yum)

8
  • @ToniMichelCaubet - the syntax Amber provides is correct, read this. You may need to do some web-searching around the problem since we don't have access to try a few other things that would come to mind if we were at your console. Do some digging :).
    – halfer
    Commented May 27, 2012 at 18:43
  • (Also the fact that some distros have sane package repositories that actually include most of the things you might want in a basic server. cough)
    – Amber
    Commented May 27, 2012 at 18:53
  • I was able to do it like this kb.liquidweb.com/install-memcached-on-centos-5 but now i have this problem stackoverflow.com/questions/10776545/… :( Commented May 27, 2012 at 19:13
  • i think this is incorrect isnt that so, because he is asking about Memcache and the given answer is for the "Memcached" two different things
    – mahen3d
    Commented Sep 26, 2013 at 2:09
  • @user1179459 memcached is the memcache server.
    – Amber
    Commented Sep 28, 2013 at 0:09
18

This may be obvious, but make sure that memcached is actually running:

service memcached start
1
  • For me, it was actually because it was running, but I had changed from the default port in /etc/memcached.conf
    – Kzqai
    Commented Feb 23, 2015 at 15:32
6

memcache is diffrent with memcached

and i thing you have installed memcache because $memcache = new Memcache(); worked

you must started it on your server

check this 10 baby steps to install Memcached Server and access it with PHP

1
  • I know, its just they work the same. I didn't really care wich one, and memcached it was.. Commented Dec 5, 2012 at 20:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.