tags:

views:

1294

answers:

5

Hi, I'm using php::memcache module to connect a local memcached server (@127.0.0.1), but I don't know that which one I should use, memcache::connect() or memcache::pconnect ? Does memcache::pconnect will consume many resource of the server?

Thank you very much for your answer!

A: 

"Consumes" TCP port.

vartec
+2  A: 

pconnect stands for persistant connection. This means that the client (in your case the script) will constantly have a connection open to your server which might not be a resouces problem - more a lack of connections available.

You should probably be wanting the standard connect unless you know you need to use persistant connections.

Ross
I'm using memcache::addServer( string $host [, int $port [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback]]]]]]] )the 3rd parameter is persistent, and the default value is TRUE.but memcache::connect() doesn't use persistent..
cyberscorpio
+1  A: 

As far as I know, the same rules that govern persistent vs. regular connections when connecting to MySQL apply to memcached as well. The upshot is, you probably shouldn't use persistent connections in either case.

Jeremy DeGroot
+4  A: 

Memcached uses a TCP connection (handshake is 3 extra packets, closing is usually 4 packets) and doesn't require any authentication. Therefore, the only upside to using a persistent connection is that you don't need to send those extra 7 packets and don't have to worry about having a leftover TIME-WAIT port for a few seconds.

Sadly, the downside of sacrificing those resources is far greater than the minor upsides. So I recommend not using persistent connections in memcached.

St. John Johnson
Thank you, I'll use memcache::connect() instead :)
cyberscorpio
No problem! Glad I could help. Please select an answer as the one that answered your question.
St. John Johnson
what exactly are the "downsides" that you say far outweigh the upsides? I am curious as I have been looking for a solid answer to this same question.
jW
A: 

In application I'm developing I use pconnect as it uses connection pool and from the view of hardware - one server keeps one connection to memcache. I don't know exactly how it works but I think memcached is smart enough to track IP of memcached client machine.

I've played with memcached for a long time and found that using memcache::getStatus shows that connections count doesn't increased when using pconnect.

You can use debug page which show memcached stats and try to tweak pconnect or connect and see what's going on.

Mr.ElectroNick