public getDriver ( ) : InfluxDB\Driver\DriverInterface | InfluxDB\Driver\QueryDriverInterface | ||
리턴 | InfluxDB\Driver\DriverInterface | InfluxDB\Driver\QueryDriverInterface |
/** * Writes points into InfluxDB * * @param Point[] $points Array of points * @param string $precision The timestamp precision (defaults to nanoseconds) * @return bool * @throws Exception */ public function writePoints(array $points, $precision = self::PRECISION_NANOSECONDS) { $payload = array_map(function (Point $point) { return (string) $point; }, $points); try { $driver = $this->client->getDriver(); $driver->setParameters(['url' => sprintf('write?db=%s&precision=%s', $this->name, $precision), 'database' => $this->name, 'method' => 'post']); // send the points to influxDB $driver->write(implode(PHP_EOL, $payload)); return $driver->isSuccess(); } catch (\Exception $e) { throw new Exception('Writing has failed', $e->getCode(), $e); } }
/** * Writes points into InfluxDB * * @param Point[] $points Array of points * @param string $precision The timestamp precision (defaults to nanoseconds) * @return bool * @throws Exception */ public function writePoints(array $points, $precision = self::PRECISION_NANOSECONDS) { $payload = array_map(function (Point $point) { return (string) $point; }, $points); try { $driver = $this->client->getDriver(); $parameters = ['url' => sprintf('write?db=%s&precision=%s', $this->name, $precision), 'database' => $this->name, 'method' => 'post']; // add authentication to the driver if needed if (!empty($this->username) && !empty($this->password)) { $parameters += ['auth' => [$this->username, $this->password]]; } $driver->setParameters($parameters); // send the points to influxDB $driver->write(implode(PHP_EOL, $payload)); return $driver->isSuccess(); } catch (\Exception $e) { throw new Exception($e->getMessage(), $e->getCode()); } }