[英]How can I get count number of connection for multiple queries?
Sometime I access my page and get error from Mysql: 有时我访问页面并从Mysql中获取错误:
Too many connections 太多联系
I fixed it by change max_connections in mysql config. 我通过更改mysql配置中的max_connections来修复它。
But I'm not sure for each request (or function, not all), how many connection be opened. 但是我不确定每个请求(或功能,不是全部)打开多少个连接。
For example, my request call the function index
: 例如,我的请求调用函数index
:
public function index($id) {
$user = DB::table('users')->find($id);
$post = DB::table('posts')->where('user_id', $user->id)->first();
$post->author = 'created by ' . $user->name;
$post->save();
}
That function just find a user, then rename author
column of first user's post. 该功能只是找到一个用户,然后重命名第一个用户的帖子的author
列。
That seem like 3 queries be executed, so how many connection be opened? 似乎要执行3个查询,因此要打开多少个连接? 3 or 1? 3或1?
How can I check the number of connection exactly? 如何准确检查连接数? something like: return number_mysql_connection;
像这样: return number_mysql_connection;
You can try following query to find number of connections 您可以尝试以下查询来查找连接数
SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"
Besides, you can avoid that Too Many Connections problem by closing the database connection in the end of the script. 此外,可以通过在脚本末尾关闭数据库连接来避免“连接过多”问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.