AsyncMysqlConnection::connectResult

Returns the AsyncMysqlConnectResult for the current connection.

Description

public function connectResult(): ?AsyncMysqlConnectResult

Returns the AsyncMysqlConnectResult for the current connection.

An AsyncMysqlConnectResult provides information about the timing for creating the current connection.

Return Values

Examples

This example shows how to get data about the async MySQL connection you made via a call to AsyncMysqlConnection::connectResult. An AsyncMysqlConnectResult is returned and there are various statistical methods you can call. Here, we call elapsedTime to show the time it took to make the connection.

Interestingly, if you run this example twice or more, you may notice that the second time on will show a lower elapsed time than the first. This could be due to caching mechanisms, etc.

<?hh

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

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

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

run();
Output
int(2078)