Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long does a mysql_connect stay open?

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

like image 919
Naftali Avatar asked Mar 22 '11 21:03

Naftali


1 Answers

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

like image 54
Frosty Z Avatar answered Sep 28 '22 21:09

Frosty Z