AsyncMysqlConnectResult::elapsedMicros

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

public function elapsedMicros(): int;

Returns

  • 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.

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_connection_time(): Awaitable<?int> {
  $pool = new \AsyncMysqlConnectionPool(darray[]);
  $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)