AsyncMysqlConnection::port

The port on which the MySQL instance is running

public function port(): int;

Returns

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

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