jW.
jW.

Reputation: 9310

Persistent connections to memcached in PHP

In our current use of memcached, we are running into problems in a high volume server because so much time is used setting up and tearing down connections to our memcache server. Would using persistent connections to memcached help alleviate this problem?

Also, what is the preferred way to connect and use persistent memcahced connections? I was thinking of setting a "pool_size" variable then randomly choosing from 1-$POOL_SIZE and using that connection

$mem = new Memcached(rand(1, $pool_size));

Either I am looking in the wrong place or there is not a lot of information on this out there.

Upvotes: 6

Views: 17872

Answers (3)

brianlmoon
brianlmoon

Reputation: 324

Both pecl/memcache and pecl/memcached support persistent connections per process. However, the bug does exist in pecl/memcached at this time.

Upvotes: 3

J. Bruni
J. Bruni

Reputation: 20490

I have read that persistent connections feature is broken in the "memcached" PHP extension.

First: the "persistent" connection is not destroyed. (This is ok.)

Second: when you try to reuse it, it creates a new one! (This is bad!)

Result: memory leaks, increasingly consuming all available RAM.

Check here: http://brian.moonspot.net/php-memcached-issues

As I said, I haven't experienced this myself - I just read this information in the linked article.

Upvotes: 1

Byron Whitlock
Byron Whitlock

Reputation: 53919

The php client doesn't handle persistent connections. you either need to use your pooling idea, or use a 3rd party memcached client for php that supports persistent connections.

like this one:

http://github.com/andreiz/php-memcached/tree/master

Upvotes: 0

Related Questions