(PHP) select memcache :: connect or memcache :: pconnect?

I use the php :: memcache module to connect the local memcached server (@ 127.0.0.1), but I don’t know which one should I use, memcache :: connect () or memcache :: pconnect? Will memcache :: pconnect consume a lot of server resources?

Thank you very much for your response!

+4
source share
6 answers

Memcached uses a TCP connection (acknowledgment of 3 additional packets, closing usually 4 packets) and does not require any authentication . Thus, the only advantage of using a persistent connection is that you do not need to send these additional 7 packets and you do not have to worry about TIME-WAIT remaining in a few seconds.

Unfortunately, the disadvantage of sacrificing these resources is much greater than minor ones. Therefore, I recommend that you do not use persistent connections in memcached.

+7
source

pconnect means a stable connection. This means that the client (in your case, the script) will constantly have a connection open to your server, which may not be a resouces problem - there are no longer any connections available.

You probably need a standard connect if you don't know what you need to use persistent connections.

+2
source

As far as I know, the same rules that govern persistent and regular connections when connecting to MySQL also apply to memcached. As a result, you probably shouldn't use persistent joins anyway.

+1
source

Consumes a TCP port.

0
source

In the application I'm developing, I use pconnect, because it uses a connection pool and in terms of hardware - one server supports one connection to memcache. I don’t know exactly how this works, but I think memcached is smart enough to keep track of the IP address of the memcached client machine.

I played with memcached for a long time and found that using memcache :: getStatus shows that the number of connections when using pconnect does not increase.

You can use the debug page, which shows memcached statistics and tries to configure pconnect or connect and see what happens.

0
source

One of the drawbacks is that PHP does not have an explicit error or warning if one or all permanently connected memcached daemons disappear (s). This is a good feature.

0
source

All Articles