dsq2015 2013-08-01 12:01
浏览 58

MySql和ADODB5 - 最大连接数

Here's an example of php code to make a connection to mysql and perform a select query using adodb :

include('adodb.inc.php');    # load code common to ADOdb
$db = &ADONewConnection('mysql'); 
$db->PConnect("localhost", "root", "password", "database");
$recordSet = &$conn->Execute('select * from products');
if (!$recordSet) 
         print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
         print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
         $recordSet->MoveNext();
}

$recordSet->Close(); # optional
$conn->Close(); # optional
?>

Do i have to use

$db = &ADONewConnection('mysql'); 
$db->PConnect("localhost", "root", "password", "database");

and

$recordSet->Close(); # optional
$conn->Close(); # optional

each time i want to make a query to unsure the error of max_connection reached ?

How can i manage when 1000 users or more are connected to my website with MySQL's max_connection = 100 ?

  • 写回答

1条回答 默认 最新

  • doumu8911 2013-08-01 15:54
    关注

    When the maximum number of connections has been reached, your $db->PConnect should throw an exception or return an error code (I don't know this driver too much, please check the man pages). You must watch this error and act accordingly in case of error. Typically, wait a few seconds, and try again a couple of times before returning an error to the user.

    Now, the max_connection is the limit of concurrent connections. 1000 users connected to your application are (hopefully) not all running a query at the same time, so you should be safe for a while. At the end of a script execution, all connections are closed (or returned to the pool in your case), and become available to other users. So you will not reach your limit of 100 unless 100 users are actually clicking at the same time on some link in your application.

    But you should write your scripts so that they open (or acquire) a connection as late as possible during the course of their execution, and close (or release) the connection as early as possible. This way, the connection is held for a span of time as short as possible, making it less likely to hit the limit.

    Now, if you do reach the limit, then there is nothing else you can do but increasing the limit. The only workaround is to put exceeding connection requests on hold (as I suggest in the first paragraph).

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题