在PHP中反复打开MySQL连接的影响是什么? [英] What are the implications of opening MySQL connections over and over again in PHP

查看:163
本文介绍了在PHP中反复打开MySQL连接的影响是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,我有一个DB类,每次调用类中的Query函数时,都会打开和关闭多个MySQL连接。我应该打开一次连接吗?

Specifically, I have a DB class that opens and closes multiple MySQL connections every time I call the Query function in the class. Should I open a connection once? or is it ok to open and close connections like this?

推荐答案

我简单的想法(ISAM,没有交易)C语言应用程序每天运行8小时,通过一个单一的MySQL连接在一个数据库中更新多个表,并保持打开整个时间。它工作正常。任何时候有任何类型的MySQL错误(不仅仅是服务器消失了),代码只是再次调用mysql_real_connect(),它选择没有任何麻烦。重新连接是我认为MySQL功能完美无缺的地方之一。

My simple-minded (ISAM, no transactions) C-language app runs for eight hours a day, updating multiple tables in one database over one single MySQL connection that stays open the whole time. It works just fine. Anytime there's any kind of MySQL error (not only server gone away), the code just calls mysql_real_connect() again and it picks right up without any trouble. Reconnection is one of the places where, in my opinion, MySQL functions flawlessly.

但是有很多争论和讨论关于持续连接的好/坏。您可以在这里找到一些:

But there's plenty of controversy and discussion about the goodness/badness of persistent connections. You can find some of it here:

http://www.google.com/webhp?hl=&sourceid=navclient-ff&rlz=1B3GGLL_enUS384US384&ie=UTF-8 #rlz = 1B3GGLL_enUS384US384& hl = zh& source = hp& q = mysql + persistent + connection& aq = 0& aqi = g4g-m5& aql =& oq = mysql + persistent + conn& gs_rfai = Ch2c6iCchTO3zG4i6MZ-i7JAOAAAAqgQFT9BAKCs& = ff274912d96214e6

- HTH

这篇关于在PHP中反复打开MySQL连接的影响是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆