2

I just installed memcached on my Mac OS X 10.6.8. It installed perfectly and when I type in memcached in Terminal I get this:

failed to listen on TCP port 11211 tcp
listen: Address already in use

And I have a script in my localhost that contains this:

$memcache = new Memcache();

But I get an error thrown saying Fatal error: Class 'Memcache' not found.

How can I get memcached to work, is it because the port 11211 is not listened to which probably doesn't make memcached work?

  • Don't go on chat to 'bump' up 5 minute old questions, things don't work that way, it'll just annoy other users who won't want to help you. – Chopper3 Jul 2 '11 at 12:47
  • I apologise for that. – MacMac Jul 2 '11 at 16:03
5

Your first error is probably because memcached is already running. If you run ps -e | grep memcache | grep -v grep you'll probably see it. The output of netstat -a -p tcp | grep LISTEN will show you all the listening services too, which may help.

The second issue is probably because you don't have a memcache extension installed for your version of PHP (from the error I'm assuming you're using PHP). You probably want http://pecl.php.net/package/memcache to solve that.

0

Memcache could already be running. I had a crashed version of memcache running and got this problem.

I found this helpful:

netstat -l --protocol=tcpip --program

Once I had the pid I killed memcache

I then edited the config

vi /etc/sysconfig/memcached

I added

OPTIONS="-l 127.0.0.1"
0

I also ran into the first error you reported:

failed to listen on TCP port 11211 tcp
listen: Address already in use

In my configuration I found the error was caused by multiple -l arguments to the same address. On Ubuntu my /etc/memcached.conf file contained:

-l localhost
-l 127.0.0.1

memcached was able to successfully bind to the first address, but because 127.0.0.1 duplicates localhost, memcached gave the Address already in use error when it tried to bind to the second address.

If you're running into this error and can't find an existing process binding to your port, double-check your memcached configuration. If you're listening for connections on multiple addresses, ensure those addresses don't represent the same address. Such a setup could cause this error.

  • Welcome to the community, please note that the question has been correctly answered before, and there is nothing I can find in common between what you have posted and what the OP's issue was, depending on the given answer. Please post technical answers, and avoid answers with no proof. BTW, your answer is not correct, so you can either remove it or edit it before anyone downvotes you. Wish you luck, and success. ;) – FarazX Mar 24 '17 at 18:52
  • Thank you for the clarification. I've expanded my answer to clarify that it address the OP's first question. I disagree that my answer is incorrect—there are multiple reasons memcached could produce an error that the address is in use. Having another instance of memcached running, as the accepted answer states, it most likely. However, I felt it might be helpful to people attempting to track down this problem to know this erro can occur without an existing instance running, and that starting an instance of memcached can produce this error. – Alex Clay Mar 26 '17 at 0:28
  • As far as I could get you, you are trying to say one of either should be used and not both. So you can easily say: "remove one of duplicates if you're using both 127.1 and localhost at the same time." But by default, in memcached.conf, there is only -l 127.0.0.1. No duplicate. On the other hand, this is not the -l option, it's just used for listening to the IP address which is 127.1 by default. Please correct your answer and provide more technical reasons. Good luck mate ;) – FarazX Mar 26 '17 at 6:29
  • BTW, you have a typo, that is memcached and not memcachd. Correct it please. – FarazX Mar 26 '17 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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