AsyncMysqlConnection::lastActivityTime

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

public function lastActivityTime(): float;

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

Returns

  • float - A float representing 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.

require __DIR__.'/../../__includes/async_mysql_connect.inc.php';

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(darray[]);
  $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)