由于框架提供的memcachewrapper内部对memcache使用方法有误,导致长连接过多,(线上四台web机器每台有4000链接连在了两台memcache服务器上)
具体bug说明参见 [url]https://bugs.php.net/bug.php?id=60460[/url]
[quote]
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.
[/quote]
亦即问题是错误的使用Memcache::addServer所致。调用addserver时,如果设置persistent为true,则此链接将不会关闭,直至web server重启;即使显示调用close也没用。而php为短执行进程,执行完毕退出后新执行脚本又发起addServer的新链接,从而导致链接数不停增加。
使用Memcache::connect则不会出现此问题,其实也就是persistent=false的形式。
对应的还可以参考
[quote]
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.
[/quote]
也是长连接
具体bug说明参见 [url]https://bugs.php.net/bug.php?id=60460[/url]
[quote]
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.
[/quote]
亦即问题是错误的使用Memcache::addServer所致。调用addserver时,如果设置persistent为true,则此链接将不会关闭,直至web server重启;即使显示调用close也没用。而php为短执行进程,执行完毕退出后新执行脚本又发起addServer的新链接,从而导致链接数不停增加。
使用Memcache::connect则不会出现此问题,其实也就是persistent=false的形式。
对应的还可以参考
[quote]
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.
[/quote]
也是长连接
解决Memcache错误配置导致的长连接问题
本文探讨了Memcache使用Memcache::addServer()导致的长连接问题,指出错误在于未正确理解默认持久连接特性。文章详细解释了Memcache::connect()与Memcache::pconnect()的区别,强调了在PHP中避免使用持久连接的重要性,以防止资源消耗过大的问题。
170

被折叠的 条评论
为什么被折叠?



