简体   繁体   English

Cakephp:是否可以限制数据库连接数?

[英]Cakephp: Is it possible to limit the number of database connections?

I read that Bluehost limits the number of database connections from one user to 15. I believe my webapp is using up all those connections. 我读到Bluehost将一个用户的数据库连接数限制为15。我相信我的Web应用程序已经用完了所有这些连接。 Whenever I try to use the cake console to access the database, I get the following error: 每当我尝试使用Cake控制台访问数据库时,都会出现以下错误:

2011-11-29 05:06:58 Warning: Warning (2): mysql_connect() [function.mysql-connect]: User myusername already has more than 'max_user_connections' active connections in [/home2/myusername/public_html/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php, line 561] 2011-11-29 05:06:58警告:警告(2):mysql_connect()[function.mysql-connect]:用户myusername在[/ home2 / myusername / public_html / myapp /中已具有超过'max_user_connections'个活动连接cake / libs / model / datasources / dbo / dbo_mysql.php,第561行]

How can I make sure there are connections for the cake console to use? 如何确保蛋糕控制台可以使用连接?

Edit: 编辑:

Just to be clear, my app is not running out of connections. 请注意,我的应用程序没有连接耗尽。 However, every time I try to access the database from the cake console I get that error. 但是, 每次我尝试从cake console访问数据库都会收到该错误。 This leads me to believe that cake is creating and holding onto the connections for some reason. 这使我相信蛋糕是出于某种原因而产生并保持联系。

If you have the root user account (or with super privileges), 如果您具有root用户帐户(或具有超级权限),
you can change cli script to connect using root, 您可以更改cli脚本以使用root进行连接,
as root connection even the max connection is reached (max + 1) 作为根连接,即使达到最大连接数(最大+1)

You can make use of php_sapi_name to distinguish between normal web access or via console. 您可以使用php_sapi_name来区分正常的Web访问还是通过控制台。

I don't think max connection is capped at 15, 我不认为最大连接数上限为15
if so you should consider another hosting company other than bluehost (because is suck) ... 如果是这样,您应该考虑除bluehost之外的其他托管公司(因为很烂)...

To verify this, issue a SQL like :- 要验证这一点,请发出如下SQL:

show variables like "max%";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM