AsyncMysqlConnection::port

Description

public function port(): int

The port on which the MySQL instance is running.

Return Values

  • int - The port as an int.

Examples

The following example shows how to get the port of the MySQL server that this connection is associated with via AsyncMysqlConnection::port.

<?hh

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

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

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

run();
Output
int(3306)