/** * Build the client from a dsn * Examples: * * https+influxdb://username:pass@localhost:8086/databasename * udp+influxdb://username:pass@localhost:4444/databasename * * @param string $dsn * @param int $timeout * @param bool $verifySSL * *@return Client|Database * @throws ClientException */ public static function fromDSN($dsn, $timeout = 0, $verifySSL = false) { $connParams = parse_url($dsn); $schemeInfo = explode('+', $connParams['scheme']); $dbName = null; $modifier = null; $scheme = $schemeInfo[0]; if (isset($schemeInfo[1])) { $modifier = strtolower($schemeInfo[0]); $scheme = $schemeInfo[1]; } if ($scheme != 'influxdb') { throw new ClientException($scheme . ' is not a valid scheme'); } $ssl = $modifier === 'https' ? true : false; $dbName = $connParams['path'] ? substr($connParams['path'], 1) : null; $client = new self($connParams['host'], $connParams['port'], $connParams['user'], $connParams['pass'], $ssl, $verifySSL, $timeout); // set the UDP driver when the DSN specifies UDP if ($modifier == 'udp') { $client->setDriver(new UDP($connParams['host'], $connParams['port'])); } return $dbName ? $client->selectDB($dbName) : $client; }