【发布时间】:2011-03-22 21:00:42
【问题描述】:
我有一个 CLI 脚本,当您第一次启动它时:
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 之前我必须检查连接是否仍然打开?
这是我得到的错误:
MySQL 错误:MySQL 服务器已消失
【问题讨论】:
-
您对此有什么问题吗?连接应该保持打开状态(除非您有一些设置限制了连接在服务器上打开的时间)。
-
是的,我有问题。基本上这是一个接受 websocket 连接的“服务器”cli。出于某种原因,当我尝试连接一天后,我得到了
MySQL Error: MySQL server has gone away错误
标签: php mysql command-line-interface