How long does mysql_connect remain open?

I have a CLI script that on first start:

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 work for several days. How can I open mysql connection? or before each mysql_query do I need to check if the whole connection is open?

This is a receiving error: MySQL Error: MySQL server has gone away

Thanks!

+4
source share
1 answer

Check this out: http://techgurulive.com/how-to-solve-mysql-server-has-gone-away-or-lost-connection-to-server-during-query-fix/

In particular, it says:

The server disconnected and closed the connection. By default, the server closes the connection after 8 hours or 28800 seconds if nothing happened. You can change the time it takes to set the wait_timeout variable when you start mysqld through your /etc/my.cnf servers [...]

+8
source

Source: https://habr.com/ru/post/1344838/


All Articles