4

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?

MacMac
  • 2,061
  • 10
  • 31
  • 38

5 Answers5

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.

Conor McDermottroe
  • 948
  • 1
  • 7
  • 17
0

I know this is an old question, but it was top of Google for me and I had a very different issue.

I had disabled ipv6 on an EC2 Amazon Linux 2 (Beanstalk) box. The standard configuration for memcached when installed from amazon-linux-extras is to require ipv6 localhost as one of the addresses to listen to.

I simply replaced the whole OPTIONS= line with

sed -i -E "s/OPTIONS=.+//g" /etc/sysconfig/memcached
echo 'OPTIONS="-l 127.0.0.1"' >> /etc/sysconfig/memcached
phil_ayres
  • 191
  • 1
  • 3
  • 12
0

In my case it was because memcached was already running. Try:

$ ps aux | grep memcache | grep -v grep 

jill.doe     93302   0.0  0.0 408916512   1888   ??  Ss   11:39am   0:00.04 memcached

You need the PID in order to kill the process:

$ kill 93302

This should at least solve the failed to listen on TCP port 11211 tcp issue.

cgl
  • 101
  • 1
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"
Tony Topper
  • 101
  • 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.

Alex Clay
  • 1
  • 1
  • 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. ;) –  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 00: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 ;) –  Mar 26 '17 at 06:29
  • BTW, you have a typo, that is `memcached` and not `memcachd`. Correct it please. –  Mar 26 '17 at 06:29