我需要尝试了解 MySQL 进程/连接是如何工作的。我用谷歌搜索并没有看到任何外行术语,所以我在这里问。这是情况。
我们的主机让我们对“太多的 MySQL 进程”感到悲痛。我们在共享服务器上。我们被允许使用 0.2 的服务器 mySQL 进程——他们声称这是 50 个连接——他们说我们使用的是 0.56。
来自技术支持代表:
“MySQL procs 数(平均) - 0.59 意味着您使用了共享服务器上可用 MySQL 连接总数的 0.59%。可接受的值为 0.20,即 50 个连接。”
这是我们正在运行的:
Zen Cart: 1.5.1 35K products. Auto updating of 1-20
products every 10 hours via cron.
PHP version 5.3.16
MySQL version 5.1.62-cll
Architecture i686
Operating system linux
我们通常在网站上每天有大约 5000 次点击,即使我在 Google 网站管理员工具中将抓取速度设置为最低,Google bot 也喜欢访问。
我希望有人可以根据这个主机在说什么向我解释 MySQL 进程。每次我问他们时,我都会得到一个模糊不清的模糊答案。每次访问者访问站点时是否都会创建一个新的 MySQL 进程?这似乎不对。
根据技术,我们当时使用了 150 个连接。
编辑:这是 zencart 中的连接功能
function connect($zf_host, $zf_user, $zf_password, $zf_database, $zf_pconnect = 'false', $zp_real = false) {
$this->database = $zf_database;
$this->user = $zf_user;
$this->host = $zf_host;
$this->password = $zf_password;
$this->pConnect = $zf_pconnect;
$this->real = $zp_real;
if (!function_exists('mysql_connect')) die ('Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP');
$connectionRetry = 10;
while (!isset($this->link) || ($this->link == FALSE && $connectionRetry !=0) )
{
$this->link = @mysql_connect($zf_host, $zf_user, $zf_password, true);
$connectionRetry--;
}
if ($this->link) {
if (@mysql_select_db($zf_database, $this->link)) {
if (defined('DB_CHARSET') && version_compare(@mysql_get_server_info(), '4.1.0', '>=')) {
@mysql_query("SET NAMES '" . DB_CHARSET . "'", $this->link);
if (function_exists('mysql_set_charset')) {
@mysql_set_charset(DB_CHARSET, $this->link);
} else {
@mysql_query("SET CHARACTER SET '" . DB_CHARSET . "'", $this->link);
}
}
$this->db_connected = true;
if (getenv('TZ') && !defined('DISABLE_MYSQL_TZ_SET')) @mysql_query("SET time_zone = '" . substr_replace(date("O"),":",-2,0) . "'", $this->link);
return true;
} else {
$this->set_error(mysql_errno(),mysql_error(), $zp_real);
return false;
}
} else {
$this->set_error(mysql_errno(),mysql_error(), $zp_real);
return false;
}