InfluxDB\Client::write PHP 메소드

write() 공개 메소드

Write data
public write ( array $parameters, string | array $payload ) : boolean
$parameters array
$payload string | array InfluxDB payload (Or array of payloads) that conform to the Line syntax.
리턴 boolean
    public function write(array $parameters, $payload)
    {
        // retrieve the driver
        $driver = $this->getDriver();
        // add authentication to the driver if needed
        if (!empty($this->username) && !empty($this->password)) {
            $parameters += ['auth' => [$this->username, $this->password]];
        }
        // set the given parameters
        $driver->setParameters($parameters);
        // send the points to influxDB
        if (is_array($payload)) {
            $driver->write(implode("\n", $payload));
        } else {
            $driver->write($payload);
        }
        return $driver->isSuccess();
    }

Usage Example

예제 #1
0
 /**
  * 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();
     foreach ($points as $point) {
         if (!$point instanceof Point) {
             throw new \InvalidArgumentException('An array of Point[] should be passed');
         }
         $payload[] = (string) $point;
     }
     return $this->client->write($this->name, implode(PHP_EOL, $payload), $precision);
 }
All Usage Examples Of InfluxDB\Client::write