memcache connect vs addServer

前端 未结 3 2075
北荒
北荒 2021-02-20 05:12

I was looking at the php docs on memcache and noticed that instead of doing
$mem->connect(\'localhost\', 11211) I can do instead
$mem->addServer

3条回答
  •  滥情空心
    2021-02-20 05:38

    connect and pconnect seem to be more low level calls, that perform a single task without much overhead. addServer OTOH is more high level, managing several servers, retrying when one of them fails, etc. I'm under the impression that the latter relies on the former to do its task.

    From the end-user perspective, there's really little advantage in using the lower level function, except perhaps as a small performance improvement (if you know you'll use the connection right away, only have a single memcached server and don't need to keep a persistent connection - or actually wants to reset it for troubleshooting etc - it might be faster to just connect on demand). Only if you need more control over the connection lifecycle (for instance if you're designing your own caching strategy) those functions will be useful.

    In other words, the fact that those functions are exposed in the API doesn't imply there will be a common use case for them. Still, it's often better to provide more tools to interact with a system than less, since it encourages platform building.

提交回复
热议问题