How long does a mysql_connect stay open?

久未见 提交于 2019-12-10 17:21:34

问题


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);
    }
}

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?

This is the error im getting:

MySQL Error: MySQL server has gone away


回答1:


Check this : https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql

In particular, it is stated:

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 [...]



来源:https://stackoverflow.com/questions/5397776/how-long-does-a-mysql-connect-stay-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!