mysql_connect保持打开状态多长时间? [英] How long does a mysql_connect stay open?
问题描述
我有一个CLI脚本,当您第一次启动它时:
I have a CLI script which when you first start it:
function __construct(){$this->connectToDatabase();}
protected function connectToDatabase(){
try{
$this->databaseName = $this->dbname;
$this->posName = $this->posName;
$this->vlog = $this->vlogName;
$this->database = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db($this->databaseName, $this->database);
}
catch(Exception $e){
$this->console($e);
}
}
此CLI脚本可以保持运行数天.我如何保持mysql连接打开?还是在每个mysql_query之前我必须检查连接是否仍然打开?
This CLI script can stay running for days. How do i keep the mysql connection open? or before each mysql_query do i have to check if the connection is still open?
这是我得到的错误:
MySQL错误:MySQL服务器已消失
MySQL Error: MySQL server has gone away
推荐答案
检查此内容:特别指出:
服务器超时并关闭了 联系.默认情况下,服务器 8小时后关闭连接或 如果没有任何反应,则为28800秒. 您可以通过以下方式更改时间限制 在以下情况下设置 wait_timeout 变量 您通过服务器的mysqld启动 /etc/my.cnf [...]
The server timed out and closed the connection. By default, the server closes the connection after 8 hours or 28800 seconds if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld via your server’s /etc/my.cnf [...]
这篇关于mysql_connect保持打开状态多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!