You are here

function apdqc_mysqli_ping in Asynchronous Prefetch Database Query Cache 7

Reconnect to the MySQL database if the connection has been lost.

Will also record the table and cache ID used.

Parameters

mysqli $mysqli: mysqlnd connection object. Passed by reference.

array $db_info: static var from 'apdqc_get_db_object'. Passed by reference.

array $tables: An array of table names.

array $cids: An array of cache IDs.

bool $async: If TRUE then this connection is being used for an async query.

bool $force_check: If TRUE then this connection will be checked.

2 calls to apdqc_mysqli_ping()
apdqc_get_db_object in ./apdqc.mysql.inc
Return a mysqli object that is ready to be used.
apdqc_query in ./apdqc.mysql.inc
Runs a query in the database.

File

./apdqc.mysql.inc, line 632
APDQC Database interface code for MySQL database servers.

Code

function apdqc_mysqli_ping(mysqli &$mysqli, array &$db_info, array $tables, array $cids, $async, $force_check = FALSE) {
  $timeout_check = max(3, $db_info['var']['wait_timeout'] - 5);
  $runtime = microtime(TRUE) - REQUEST_TIME;
  if ($runtime > $timeout_check || $force_check) {
    if (empty($mysqli) || !@$mysqli
      ->ping()) {
      unset($db_info['pool'][$mysqli->thread_id]);
      $mysqli = apdqc_mysqli_new_connection($db_info, TRUE);
      if (empty($mysqli) || !@$mysqli
        ->ping()) {
        $mysqli = FALSE;
      }
    }
  }
  if (!empty($mysqli)) {
    $db_info['pool'][$mysqli->thread_id] = array(
      $mysqli,
      $tables,
      $cids,
      $async,
    );
  }
}