AsyncMysqlConnection::lastActivityTime

Last time a successful activity was made in the current connection, in seconds since epoch

Description

public function lastActivityTime(): float

The first successful activity of the current connection is its creation.

Return Values

  • float - A float representing the the number of seconds ago since epoch that we had successful activity on the current connection.

Examples

This example shows how to determine the last time a successful call was made using a given connection via AsyncMysqlConnection::lastActivityTime. The value returned is seconds since epoch as a float.

<?hh

namespace Hack\UserDocumentation\API\Examples\AsyncMysql\Conn\LastActTime;

use \Hack\UserDocumentation\API\Examples\AsyncMysql\ConnectionInfo as CI;

async function connect(\AsyncMysqlConnectionPool $pool):
  Awaitable<\AsyncMysqlConnection> {
  return await $pool->connect(
    CI::$host,
    CI::$port,
    CI::$db,
    CI::$user,
    CI::$passwd
  );
}
async function get_time(): Awaitable<float> {
  $pool = new \AsyncMysqlConnectionPool(array());
  $conn = await connect($pool);
  $t = $conn->lastActivityTime();
  $conn->close();
  return $t;
}

function run(): void {
  $t = \HH\Asio\join(get_time());
  var_dump($t);
}

run();
Output
float(1447364890.3616)