memcache php 长连接

由于框架提供的memcachewrapper内部对memcache使用方法有误,导致长连接过多,(线上四台web机器每台有4000链接连在了两台memcache服务器上)

具体bug说明参见 https://bugs.php.net/bug.php?id=60460
引用

Memcache::addServer() does a *presistent* connection by default, if you do not
specify it to be different.

memcache::close() function doesn't close persistent connections, which are closed
only during web-server shutdown/restart.

so this is not a bug at all, but a coding error.

亦即问题是错误的使用Memcache::addServer所致。调用addserver时,如果设置persistent为true,则此链接将不会关闭,直至web server重启;即使显示调用close也没用。而php为短执行进程,执行完毕退出后新执行脚本又发起addServer的新链接,从而导致链接数不停增加。

使用Memcache::connect则不会出现此问题,其实也就是persistent=false的形式。

对应的还可以参考
引用

Memcache::pconnect()is similar to Memcache::connect() with the difference, that the connection it establishes is persistent. This connection is not closed after the end of script execution and by Memcache::close() function.

也是长连接

猜你喜欢

转载自ggsonic.iteye.com/blog/1418307