PWE keep db connection up

This commit is contained in:
fbsanchez 2019-11-18 11:06:27 +01:00
parent 1cacbbc08f
commit 99b0714850
1 changed files with 24 additions and 0 deletions

View File

@ -439,6 +439,9 @@ abstract class WebSocketServer
if ((time() - $this->lastTickTimestamp) > $this->tickInterval) {
$this->lastTickTimestamp = time();
$this->tick();
// Keep connection with DB active.
$this->dbHearthbeat();
}
socket_select($read, $write, $except, 0, $this->timeout);
@ -1530,4 +1533,25 @@ abstract class WebSocketServer
}
/**
* Keeps db connection opened.
*
* @return void
*/
public function dbHearthbeat()
{
global $config;
\hd($config['dbconnection']);
if (isset($config['dbconnection']) === false
|| mysqli_ping($config['dbconnection']) === false
) {
// Retry connection.
db_select_engine();
$config['dbconnection'] = db_connect();
}
}
}