Example #1
0
 /**
  * Build the client from a dsn
  *
  * Example: https+influxdb://username:pass@localhost:8086/databasename', timeout=5
  *
  * @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 = $schemeInfo[0];
         $scheme = $schemeInfo[1];
     }
     if ($scheme != 'influxdb') {
         throw new ClientException(sprintf('%s is not a valid scheme', $scheme));
     }
     $ssl = $modifier && $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);
     return $dbName ? $client->selectDB($dbName) : $client;
 }
Example #2
0
 /**
  * Build the client from a dsn
  * Examples:
  *
  * udp+influxdb://username:pass@localhost:4444/databasename
  *
  * @param  string $dsn
  *
  * @return Client|Database
  * @throws ClientException
  */
 public static function fromDSN($dsn)
 {
     $connParams = parse_url($dsn);
     $schemeInfo = explode('+', $connParams['scheme']);
     $modifier = null;
     $scheme = $schemeInfo[0];
     $dbName = isset($connParams['path']) ? substr($connParams['path'], 1) : null;
     if (isset($schemeInfo[1])) {
         $modifier = strtolower($schemeInfo[0]);
         $scheme = $schemeInfo[1];
     }
     if ($scheme != 'influxdb') {
         throw new ClientException($scheme . ' is not a valid scheme');
     }
     if (!in_array($modifier, ['udp'])) {
         throw new ClientException(sprintf("%s modifier specified in DSN is not supported", $modifier));
     }
     $driver = null;
     // set the UDP driver when the DSN specifies UDP
     if ($modifier == 'udp') {
         $driver = new UDP($connParams['host'], $connParams['port']);
     }
     $client = new self($driver);
     return $dbName ? $client->selectDB($dbName) : $client;
 }
Example #3
0
 /**
 * 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;
 }