AsyncMysqlConnectResult::elapsedMicros

The total time for the establishment of the MySQL connection, in microseconds

Description

public function elapsedMicros(): int

Return Values

  • int - the total establishing connection time as int microseconds.

Examples

Every connection has a connection result. You get the connection result from a call to AsyncMysqlConnection::connectResult. And one of the methods on an AsyncMysqlConnectResult is elapsedMicros(), which tells you how long it took to make the connection.

<?hh

namespace Hack\UserDocumentation\API\Examples\AsyncMysql\ConnResult\ElapsedMic;

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_connection_time(): Awaitable<int> {
  $pool = new \AsyncMysqlConnectionPool(array());
  $conn = await connect($pool);
  $em = $conn->connectResult()->elapsedMicros();
  $conn->close();
  return $em;
}

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

run();
Output
int(2459)